Java 从另一个类请求double时出错

Java 从另一个类请求double时出错,java,class,double,Java,Class,Double,我需要制作一个菜单,这样用户就可以选择他想用我正在构建的银行应用程序做什么。 用户有以下选项: >1. Select a bank account. >2. Check the account balance. >3. Depositing money into the account >4. Withdraw money from the account >5. Transfer money from one account to another accoun

我需要制作一个菜单,这样用户就可以选择他想用我正在构建的银行应用程序做什么。 用户有以下选项:

>1. Select a bank account. 
>2. Check the account balance.
>3. Depositing money into the account 
>4. Withdraw money from the account
>5. Transfer money from one account to another account 
为了启用此功能,我们将向BankAccountService添加以下方法,如您在下面的UML方案中所见

>1. getAccount (String accountNumber)
>2. getAccountBalance (Account account)
>3. deposit (Account account, double amount)
>4. withdraw (Account account, double amount) 
>5. transfer (Account source, Account target, double amount)

正如您所看到的,当我尝试添加该方法时,会出现一个错误。

请记住,我以前从未编码过,我不知道为什么会显示此错误。 谁能告诉我添加此方法的正确方法

通过添加以下代码,我找到了获取主文件夹中所有帐户余额的方法:

double balance = bankAccountService.getAccountBalance();
System.out.println(balance);
double balance2 = account1.balance;
System.out.println(balance2);
double balance3 = account2.balance;
System.out.println(balance3);
但是在UML中,它要求我在BankAccountService中添加代码。
如果您可以从main执行此操作,我不知道为什么需要此操作。

如果BankAccount中的balance属性为private,您应该为其创建一个getter,然后:

public void getAccountBalance(BankAccount account) {
    double accountBalance = account.getBalance();
}
因此,在BankAccount.java中,您应该添加:

public double getBalance() {
   return this.balance;
}

谢谢你的回复,我应该可以这样做吗<代码>公共作废getAccountBalance(银行账户){double accountBalance=account.getBalance();}公共作废存款(银行账户){double depositAmount=account.deposit();}公共作废取款(银行账户){double depositAmount=account.Draw();}public void transfer(BankAccount account){double transferAmount=account.transfer();}Yes,但请确保在BankAccount.java中为每个帐户编写一个公共函数。对于存款,它应该有一个double-like的输入:
公共无效存款(双倍金额){this.balance+=amount;}
并在服务中使用它:
公共无效存款(银行帐户,双倍金额){account.deposit(amount);}
由于更改了属性的值,所以不要使用final关键字。
public double getBalance() {
   return this.balance;
}