我正在编写一个程序来跟踪随着时间的推移完成的不同交易。我有一个主类,还有另一个名为
CheckingAccount.java
.
我有一个以这种方式格式化的主类。
public class Main
{
public static void main (String[] args)
{
CheckingAccount c = new CheckingAccount(bal);
--line of code---
--line of code---
--line of code---
}
public static int getTransCode()
{
--line of code---
}
public static double getTransAmt()
{
--line of code---
}
public static void processCheck(double trAm, int tCode, boolean monthCh)
{
double curCharge=0.15;
CheckingAccount.setBalance(trAm,tCode,curCharge,monthCh);
CheckingAccount.setServiceCharge(curCharge);
}
public static void processDeposit(double trAm, int tCode, boolean monthCh)
{
double curCharge=0.10;
CheckingAccount.setBalance(trAm,tCode,curCharge,monthCh);
CheckingAccount.setServiceCharge(curCharge);
}
}
这是我的 CheckingAccount.java
public class CheckingAccount
{
private double balance;
private double totalServiceCharge;
public CheckingAccount(double initialBalance)
{
balance = initialBalance;
totalServiceCharge = totalServiceCharge;
}
public double getBalance()
{
return balance;
}
public void setBalance(double tAm, int Code, double charge, boolean mChrg)
{
if(tCode == 1)
balance = (balance - tAm) - charge;
else //if(tCode == 2)
balance = (balance + tAm) - charge;
}
public double getServiceCharge()
{
return totalServiceCharge;
}
public void setServiceCharge(double currentServiceCharge)
{
totalServiceCharge = totalServiceCharge+currentServiceCharge;
}
}
因此,我无法工作的行在我的主类的函数内部CheckingAccount.setBalance()
。CheckingAccount.setServiceCharge()
我要做的是从我在主类(和)上创建的函数中调用我在类中创建的方法(和setBalance
)。setServiceCharge
processCheck
processDeposit
但我无法让它运行,我继续运行这些错误消息。
不能从静态上下文中引用非静态方法 setBalance(double,int,double,boolean) CheckingAccount.setBalance(trAm,tCode,curCharge,monthCh);