我是 Java 新手。我很抱歉這么長(zhǎng)。直接下面是我的代碼到目前為止的輸出帶有**的部分是我遇到問(wèn)題的地方。我應(yīng)該比較兩個(gè) Car 對(duì)象的速度,但每個(gè) Owner 對(duì)象要么是“安全”的,要么是“魯莽的”驅(qū)動(dòng)程序。如果他們魯莽,當(dāng)他們加速時(shí),他們會(huì)加速 10。如果他們是安全的,他們會(huì)加速 5。到目前為止,這方面是有效的,但是,只有第一個(gè) Owner 對(duì)象會(huì)存儲(chǔ)信息。因此,無(wú)論第一個(gè) Owner 對(duì)象是什么(Safe/rash),它們都會(huì)是。這不會(huì)發(fā)生在我的 Car 對(duì)象上,因?yàn)槊總€(gè)單獨(dú)的對(duì)象都存儲(chǔ)了正確的信息,而這正是我遇到困難的地方。誰(shuí)能幫我弄清楚為什么?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 新手。我很抱歉這么長(zhǎng)。直接下面是我的代碼到目前為止的輸出帶有**的部分是我遇到問(wèn)題的地方。我應(yīng)該比較兩個(gè) Car 對(duì)象的速度,但每個(gè) Owner 對(duì)象要么是“安全”的,要么是“魯莽的”驅(qū)動(dòng)程序。如果他們魯莽,當(dāng)他們加速時(shí),他們會(huì)加速 10。如果他們是安全的,他們會(huì)加速 5。到目前為止,這方面是有效的,但是,只有第一個(gè) Owner 對(duì)象會(huì)存儲(chǔ)信息。因此,無(wú)論第一個(gè) Owner 對(duì)象是什么(Safe/rash),它們都會(huì)是。這不會(huì)發(fā)生在我的 Car 對(duì)象上,因?yàn)槊總€(gè)單獨(dú)的對(duì)象都存儲(chǔ)了正確的信息,而這正是我遇到困難的地方。誰(shuí)能幫我弄清楚為什么?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貢獻(xiàn)1780條經(jīng)驗(yàn) 獲得超4個(gè)贊
雙方car
并car2
得到相同的owner
構(gòu)造函數(shù)實(shí)例。其中之一應(yīng)該是owner2
。
car2 = new Car(carName, yearModel, make, model, mileage, speed, owner2); // here ^
添加回答
舉報(bào)
0/150
提交
取消