저는 Java로 프로젝트를하고 있는데, 그 부분에 붙어 있습니다. 예금 기능이 SavingsAccount 클래스에서 작동하지만 엔진 클래스에서 호출하는 방법을 알아낼 수 없습니다. 우리 프로젝트에서 BlueJ 가상 머신을 사용하여 사용자가 여러 은행 계좌를 만들고 그 사이에 자금을 이체 할 수 있도록해야합니다. 내 엔진 클래스와 저축 예금 클래스에 대한 관련 코드를 게시 할 예정입니다 ... 감사합니다. 도움을 주시면 감사하겠습니다!은행 계좌 이관 프로젝트 Java
문제점 : 한 계좌에서 다른 계좌로 송금 할 수 없는데 엔진 클래스에 오류 메시지가 표시됩니다. 나는
저축 계정 코드
public class SavingsAccount extends BankAccount
public void transfer (BankAccount that, double amount)
{
if
(balance-amount < -80)
balance = balance ;
else
{
if
(amount <= balance)
{
this.balance = this.balance - amount;
that.balance = that.balance + amount;
}
else
{
this.balance = this.balance - amount-20;
that.balance = that.balance + amount;
}
}
}
엔진 클래스
public class engine
{
SavingsAccount savings1 = new SavingsAccount();
savings1.balance = 0;
//code for other choices, such as deposit and withdraw...
if (selection2 == 3)
{
System.out.println ("How much would you like to transfer?");
int transferAmount = in.nextInt ();
System.out.println ("Which account would you like to transfer the money to?");
String thatAccount = in.next();
savings1.withdraw (transferAmount);
thatAccount.deposit (transferAmount);
System.out.println ("You account balance is " + savings1.getBalance() + "!");
}
나는 당신의 질문을 undestand하지 않습니다. –
지금까지 무엇을하고 있는지, 돈이 어디에 포함되어 있는지 이중으로 사용해서는 안됩니다. 대신 BigDecimal을 사용하십시오. –
한 계좌에서 다른 계좌로 돈을 송금 할 수 없으며 엔진 클래스에서 오류가 발생합니다. 나는 내가 돈을 보내고있는 계좌로 뭔가 잘못하고 있다고 생각한다. – user1691618