我正在使用程序類來嘗試測試我的對象類中的方法以查看它們是否工作。這是一個燃氣表讀數系統,我試圖存入資金來償還客戶欠款的餘額。爲什麼我的方法沒有返回字符串?
我的對象類組成:
package GasAccountPracticeOne;
public class GasAccountPracticeOne
{
private int intAccRefNo;
private String strName;
private String strAddress;
private double dblBalance = 0;
private double dblUnits;
private double dblUnitCost = 0.02;
public GasAccountPracticeOne(int intNewAccRefNo, String strNewName, String strNewAddress, double dblNewUnits)
{
intAccRefNo = intNewAccRefNo;
strName = strNewName;
strAddress = strNewAddress;
dblUnits = dblNewUnits;
}//end of constructor
public GasAccountPracticeOne(int intNewAccRefNo, String strNewName, String `strNewAddress)
{
intAccRefNo = intNewAccRefNo;
strName = strNewName;
strAddress = strNewAddress;
}//end of overloading contructor
public String deposit(double dblDepositAmount)
{
dblBalance = dblBalance - dblDepositAmount;
return "Balance updated";
}
在我的程序類我已經寫:
System.out.println("Enter deposit amount");
dblDepositAmount=input.nextDouble();
firstAccount.deposit(dblDepositAmount);
但在存款法我的對象類的我都問了一個字符串說回「餘額更新「將被退回。
當我運行測試時,沒有字符串返回。把我的頭從桌子上撥開 - 我做了一件荒謬的事情嗎?
您將需要打印返回值:-) – Bart 2013-03-20 18:34:00