我是 Java 新手。我很抱歉这么长。直接下面是我的代码到目前为止的输出带有**的部分是我遇到问题的地方。我应该比较两个 Car 对象的速度,但每个 Owner 对象要么是“安全”的,要么是“鲁莽的”驱动程序。如果他们鲁莽,当他们加速时,他们会加速 10。如果他们是安全的,他们会加速 5。到目前为止,这方面是有效的,但是,只有第一个 Owner 对象会存储信息。因此,无论第一个 Owner 对象是什么(Safe/rash),它们都会是。这不会发生在我的 Car 对象上,因为每个单独的对象都存储了正确的信息,而这正是我遇到困难的地方。谁能帮我弄清楚为什么?Car Name: BettyYear: 2002Car Make: KiaCar Model: SoulCar Mileage: 50000Car Speed: 65Car owner name: JaneCar owner type: rashCar Name: DukeYear: 2002Car Make: FordCar Model: F250Car Mileage: 50000Car Speed: 65Car owner name: JohnCar owner type: safeBetty is a 2002 Kia Soul.The current mileage is 50000 and current speed is 65.Jane is the owner of the car and is a rash driver.Duke is a 2002 Ford F250.The current mileage is 50000 and current speed is 65.**Jane is the owner of the car and is a rash driver.**The total mileage of both cars is 100000Betty is going 75.**Duke is going 75.**我是 Java 新手。我很抱歉这么长。直接下面是我的代码到目前为止的输出带有**的部分是我遇到问题的地方。我应该比较两个 Car 对象的速度,但每个 Owner 对象要么是“安全”的,要么是“鲁莽的”驱动程序。如果他们鲁莽,当他们加速时,他们会加速 10。如果他们是安全的,他们会加速 5。到目前为止,这方面是有效的,但是,只有第一个 Owner 对象会存储信息。因此,无论第一个 Owner 对象是什么(Safe/rash),它们都会是。这不会发生在我的 Car 对象上,因为每个单独的对象都存储了正确的信息,而这正是我遇到困难的地方。谁能帮我弄清楚为什么?Car Name: BettyYear: 2002Car Make: KiaCar Model: SoulCar Mileage: 50000Car Speed: 65Car owner name: JaneCar owner type: rashCar Name: DukeYear: 2002Car Make: FordCar Model: F250Car Mileage: 50000Car Speed: 65Car owner name: JohnCar owner type: safeBetty is a 2002 Kia Soul.The current mileage is 50000 and current speed is 65.Jane is the owner of the car and is a rash driver.Duke is a 2002 Ford F250.The current mileage is 50000 and current speed is 65.**Jane is the owner of the car and is a rash driver.**The total mileage of both cars is 100000Betty is going 75.**Duke is going 75.**
1 回答
Helenr
TA贡献1780条经验 获得超4个赞
双方car
并car2
得到相同的owner
构造函数实例。其中之一应该是owner2
。
car2 = new Car(carName, yearModel, make, model, mileage, speed, owner2); // here ^
添加回答
举报
0/150
提交
取消