0

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

客户:姓名、地址、汽车清单(包括品牌、型号和注册号)

访问:日期,所有者,汽车,完成工作的描述,下次访问日期

在主要方法中,我需要模拟两个客户端的创建,每个客户端有 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);

当我调试汽车是否属于特定客户时,它们似乎是单独声明的,客户没有汽车。访问类也正确实现了吗?我哪里错了?谢谢

4

1 回答 1

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
{
 ...
}
于 2013-02-10T19:27:01.723 回答