-3
所以首先我要交那麼代碼生病解釋我的問題故障與返回此和@override編程
import java.util.*;
class Loader
{
protected int BucketSize;
protected int bucket;
protected int price;
public void SetBucketSize(int b)
{
Scanner input = new Scanner(System.in);
System.out.println("What Bucket Size (1-5)?");
bucket = input.nextInt();
while (bucket <6)
{
System.out.println("Enter valid Bucket Size(1-5)");
}
if (bucket == 1)
{
price = 100;
}
if (bucket == 2)
{
price = 200;
}
if (bucket == 3)
{
price = 300;
}
if (bucket == 4)
{
price = 400;
}
if (bucket == 5)
{
price = 500;
}
b = price;
price = BucketSize;
}
public void GetBucketSize()
{
return this.BucketSize;
}
@Override
public void setRentalProfit()
{
RentalProfit = (RentalRate * RentalDays);
}
@Override
public String toString() {
return "Tractor (Rental days = " + RentalDays + ", Rental Rate = " + RentalRate +
", Rental profit = " + RentalProfit + ", VehicleID = " + VehicleID + BucketSize + ")";
}
}
繼承人的錯誤:像RentalDays和其他變量
Loader.java:46: error: incompatible types: unexpected return value
return this.BucketSize;
^
Loader.java:49: error: method does not override or implement a method from a supertype
@Override
^
Loader.java:52: error: cannot find symbol
RentalProfit = (RentalRate * RentalDays);
^
symbol: variable RentalProfit
location: class Loader
Loader.java:52: error: cannot find symbol
RentalProfit = (RentalRate * RentalDays);
^
symbol: variable RentalRate
location: class Loader
Loader.java:52: error: cannot find symbol
RentalProfit = (RentalRate * RentalDays);
^
symbol: variable RentalDays
location: class Loader
Loader.java:57: error: cannot find symbol
return "Tractor (Rental days = " + RentalDays + ", Rental Rate = " + RentalRate +
事在另一課我只是在這裏做什麼。我無法弄清楚爲什麼它告訴我返回thisBucketSize是一個不兼容的類型,我也不確定爲什麼它沒有找到同一個final中另一個類中的RentalDays和變量。任何幫助/提示,將不勝感激
我建議你學習Java語法。你正在做一個void方法的返回,在我們的聲明中使用一個變量。請逐一閱讀編譯錯誤並一次修復一個錯誤。 –
除此之外,將程序縮小到最小可能的大小通常是有幫助的,然後修復所有錯誤,擴展一點,修復所有錯誤,並重復這些操作直到完成。在這種情況下,你可以減少'SetBucketSize()'只詢問問題,然後從那裏緩慢擴展。 – Carpetsmoker