在程序开始时,我得到了class BusinessAccount extends GasAccount
. GasAccount
既是超类又BusinessAccount
是子类。
我也遇到了底部的重载方法的问题,这意味着要覆盖超类方法来计算对象的余额,GasAccount
并将对象的折扣应用于新单位的成本,而新单位的成本又将添加到当前余额中的一个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
任何帮助都会很棒!