Java double.MAX_VALUE?
对于我的任务,我必须为天然气公司创建一个燃气表系统,以允许员工创建新的客户帐户并修改名称和单位成本等数据,以及从他们的帐户中取出(存入)钱。
我已经创建了我的构造函数,甚至添加了一种重载方法,尽管我目前在启动我命名为存款的方法之一时遇到了问题,这应该从用户帐户中取钱,而其他方法(如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;
}
}