对于我的任务,我必须创建一个气量计系统的燃气公司,让员工创造新的负荷消费账户,并与服用(存放)钱从自己的帐户以及修改姓名和单位成本等数据。
我创建了我的构造,甚至在重载的方法加入,虽然我目前运行到一个问题开始时我的方法之一,我叫押金 ,这应该从用户帐户拿钱,而其他的方法,如recordUnits允许员工进口多少单位客户使用的燃气表读数,并更新客户帐户,这基本上是什么客户欠公司的平衡。
当只有预置信息测试程序尝试启动存款方法我得到这个时
Account.deposit(Double.MAX_VALUE);
我也不太清楚这是什么意思,似乎无法找到让过去吧反正!
测试数据和代码如下所示:
public class TestGasAccount
{
public static void main (String [] args)
{
GasAccount Account = new GasAccount (223,"Havana","TQ",1000);
Account.getAccNo();
Account.getName();
Account.getAddress();
Account.getUnits();
Account.getBalance();
Account.recordUnits(1000);
Account.getUnits();
Account.getBalance();
Account.deposit(Double.MAX_VALUE);
}
}
打破
public class GasAccount
{
private int intAccNo;
private String strName;
private String strAddress;
private double dblBalance;
private double dblUnits;
protected double dblUnitCost = 0.02;
public GasAccount(int intNewAccNo,String strNewName,String strNewAddress,double dblNewUnits)
{
intAccNo = intNewAccNo;
strName = strNewName;
strAddress = strNewAddress;
dblUnits = dblNewUnits;
dblBalance = dblNewUnits * dblUnitCost;
}
public GasAccount (int intNewAccNo, String strNewName, String strNewAddress)
{
intAccNo = intNewAccNo;
strName = strNewName;
strAddress = strNewAddress;
}
public double deposit (Double dblDepositAmount)
{
dblBalance = dblBalance - dblDepositAmount;
return dblBalance;
}
public String recordUnits (double dblUnitsUsed)
{
double dblTempBalance;
dblTempBalance = dblUnitsUsed * dblUnitCost;
dblBalance = dblBalance + dblTempBalance;
dblUnits = dblUnits + dblUnitsUsed;
return "Transaction Successful";
}
public int getAccNo ()
{
System.out.println(intAccNo);
return intAccNo;
}
public String getName()
{
System.out.println(strName);
return strName;
}
public String getAddress()
{
System.out.println(strAddress);
return strName;
}
public double getBalance()
{
System.out.println("£"+dblBalance);
return dblBalance;
}
public double getUnitCost()
{
return dblUnitCost;
}
public double getUnits ()
{
System.out.println(dblUnits);
return dblUnits;
}
public void updateUnitCost (double dblNewUnitCost)
{
dblUnitCost = dblNewUnitCost;
}
}