在程序開始時我有class BusinessAccount extends GasAccount
。 GasAccount
是超類,BusinessAccount
是子類。我已經做了超類的子類,但它不承認「擴展」
我也有問題的底部重載方法,這意味着重寫超類方法來計算對象的折扣對象的折扣適用於新單位的成本的對象的餘額將 添加到BusinessAccount
對象的當前餘額中。此方法將返回String
值 ,指示事務已成功或失敗。 我對這種方法有以下代碼
import java.util.Scanner ;
class BusinessAccount extends GasAccount
{
// The objects properties are declared as private
private double dblDiscount ;
// The objects methods are defined as public
public BusinessAccount (int intNewAccRefNo, String strNewName, String
strNewAddress,double dblNewUnits, double dblNewDiscount, int intAccRefNo, String strName, double dblUnits, String strAddress)
{
// The constructor - same name as the class and no return type
dblDiscount = dblNewDiscount;
}
public void setNewDiscount (double dblNewDiscount)
{
dblDiscount = dblNewDiscount ;
} // end of setNewDiscount
public double getDiscount()
{
return dblDiscount ;
} // end of getDiscount method
public string recordUnits ( double dblUnitsUsed);
if (dblDiscount = 0.00){
dblBalance = (dblUnitCost * dblUnitsUsed) + dblBalance;
return "Successful";
}
else {
dblBalance = ((dblUnitCost * dblUnitUSed) \ 100 * dblDiscount) + dblBalance;
return "Unseccfessful";
} // end of Override method
} // end of class
任何幫助將是偉大的!
後整個代碼,請!沒有任何東西可以用這些微不足道的信息來推斷! – NINCOMPOOP 2013-04-21 17:17:12
'public double recordUnits'如果你說它返回'double',則返回'double';如果你想返回一個'String',就這麼說。 – 2013-04-21 17:17:24
根據您的描述,聽起來像您的第一個問題是您的BusinessAccount類不公開。類聲明看起來應該像'public class BusinessAccount extends GasAccount'。 – Laf 2013-04-21 17:18:52