2013-02-10 29 views
0

我正在为一个机械记录系统进行简单模拟,其中将包含客户列表及其详细信息;每个都有他们拥有的汽车列表。每次访问也将被记录。记录客户的系统列表,每个列表的车辆列表

客户:姓名,地址,汽车(含品牌,型号和reg号)的列表

访问日期,业主,汽车,工作说明做,下次访问

日期在主我需要模拟两个客户端的创建,每个客户端有5个汽车。数据将被硬编码。然后需要添加7次访问并显示所有信息。

class Human 
{ 

    int id; 

    public int Id 
    { 
     get { return id; } 
     set { id = value; } 
    } 

    private string name; 

    public string Name 
    { 
     get { return name; } 
     set { name = value; } 
    } 

    private string address; 

    public string Address 
    { 
     get { return address; } 
     set { address = value; } 
    } 
} 

class Customer : Human 
{ 
    public LinkedList<Car> Cars = new LinkedList<Car>(); 

    public Customer() 
    { 

    } 


} 

public class Visit 
{ 


    public int visitId { get; set; } 
    public DateTime DateTimeVisited { get; set; } 
    public string customer { get; set; } 
    public string Discussion { get; set; } 

    public DateTime NextDateTimetoVisit { get; set; } 

} 

class Mechanic :Human 
{ 

    public LinkedList<Customer> customerDetails; 

    public LinkedList<Visit> visitDetails; 

    public LinkedList<Car> carDetails; 

    public Mechanic() 
    { 
     customerDetails = new LinkedList<Customer>(); 

     visitDetails = new LinkedList<Visit>(); 

     carDetails = new LinkedList<Car>(); 

    } 

    public void AddCustomer(Customer c) 
    { 

     customerDetails.AddLast(c); 
    } 

    public void AddVisit(Visit v) 
    { 

     visitDetails.AddLast(v); 
    } 



    public LinkedList<Customer> ViewCustomer() 
    { 

      return customerDetails; 
    } 

    public LinkedList<Visit> ViewVisit() 
    { 

     return visitDetails; 
    } 


    public void AddCar(Car car) 
    { 

     carDetails.AddLast(car); 
    } 


} 

//主

//Create customer 
        Customer customer1 = new Customer(); 
        Customer customer2 = new Customer(); 

        customer1.Id = 1; 
        customer1.Name = "Brandon Spiteri"; 
        customer1.Address = "22, St. George's St. B'bugia"; 

        mech1.AddCustomer(customer1); 

        Car car1 = new Car(); 

        car1.carmake = "Hyundai"; 
        car1.carmodelnum = "HJ30NAEJJ"; 
        car1.carregnum = "BAH 864"; 
        car1.Id = 1; //check 

        mech1.AddCar(car1); 


        //mech1.AddCar(car1); 

        Car car2 = new Car(); 

        car2.carmake = "Citroen"; 
        car2.carmodelnum = "HJ30NAEJJ"; 
        car2.carregnum = "IBE 554"; 
        car2.Id = 1; 
        mech1.AddCar(car2); 

        Car car3 = new Car(); 


        car3.carmake = "Toyota"; 
        car3.carmodelnum = "HJ30NAEJJ"; 
        car3.carregnum = "DAP 691"; 
        car3.Id = 1; 
        mech1.AddCar(car3); 

        Car car4 = new Car(); 

        car4.carmake = "Nissan"; 
        car4.carmodelnum = "HJ30NAEJJ"; 
        car4.carregnum = "EBD 482"; 
        car4.Id = 1; 
        mech1.AddCar(car4); 

        Car car5 = new Car(); 

        car5.carmake = "Rover"; 
        car5.carmodelnum = "HJ30NAEJJ"; 
        car5.carregnum = "BAD 505"; 
        car5.Id = 1; 
        mech1.AddCar(car5); 




        customer2.Id = 2; 
        customer2.Name = "George Spiteri"; 
        customer2.Address = "6, Dun A. Gambin St. Santa Lucija"; 

        mech1.AddCustomer(customer2); 

        Car car6 = new Car(); 

        car6.carmake = "Mercedes"; 
        car6.carmodelnum = "HJ30NAEJJ"; 
        car6.carregnum = "BAH 864"; 
        car6.Id = 2; 
        mech1.AddCar(car6); 

        Car car7 = new Car(); 

        car7.carmake = "BMW"; 
        car7.carmodelnum = "HJ30NAEJJ"; 
        car7.carregnum = "EFG 426"; 
        car7.Id = 2; 
        mech1.AddCar(car7); 

        Car car8 = new Car(); 

        car8.carmake = "Peugeot"; 
        car8.carmodelnum = "HJ30NAEJJ"; 
        car8.carregnum = "IHJ 376"; 
        car8.Id = 2; 
        mech1.AddCar(car8); 

        Car car9 = new Car(); 

        car9.carmake = "Mazda"; 
        car9.carmodelnum = "HJ30NAEJJ"; 
        car9.carregnum = "ADL 693"; 
        car9.Id = 2; 
        mech1.AddCar(car9); 

        Car car10 = new Car(); 

        car10.carmake = "Ford"; 
        car10.carmodelnum = "HJ30NAEJJ"; 
        car10.carregnum = "RGJ 486"; 
        car10.Id = 2; 
        mech1.AddCar(car10); 

当我调试,看看是否车是特定的客户下,他们似乎另行申报和客户有没有车。 Visit类是否正确实现?我哪里错了?感谢

回答

0

移动所有列表以及该方法AddCar基类这样的:

class Human 
{ 
public LinkedList<Customer> customerDetails; 

public LinkedList<Visit> visitDetails; 

public LinkedList<Car> carDetails; 

public void AddCar(Car car) 
{ 

    carDetails.AddLast(car); 
} 
... 
} 

class Customer:public Human 
{ 
... 
} 
+0

那是因为我与改变的类继承和使用customer1.AddCar(car5)实验;而不是mech1.AddCar(car5);但他们都没有解决。 – jovicks 2013-02-10 20:02:48

+0

好的,现在我明白了:你需要从Mechanic中删除public void AddCar(Car car)到基类Human!否则客户没有这种方法! – duDE 2013-02-10 20:06:35

+0

感谢您的回复。我按你告诉我的方式做了,但我在声明中发现一个错误:carDetails.AddLast(car);方法是:“对象引用未设置为对象的实例”。有什么我需要补充吗? – jovicks 2013-02-11 16:52:12