我的最后一种方法有问题。我被告知我必须在我的银行类的每月费用方法中使用我的 BankAccount.class 中的调整方法,但我无法弄清楚。我尝试了多种不同的方法,但无法使其正常工作。我们需要用月费调整账户余额。
Bank.java:33:错误:BankAccount 类中的方法调整不能应用于给定类型;BankAccount.adjust(); ^
必需:双重发现:无参数原因:实际参数列表和正式参数列表长度不同 1 错误
Bank.java:33: 错误:double 不能被取消引用 fee.adjust(); 1 个错误
Bank.java:33: 错误:找不到符号 bank.BankAccount.adjust(); 符号:变量 BankAccount 位置:BankAccount[] 类型的变量银行 1 错误
BankAccount.class
public class BankAccount {
String owner; // owner of account
int accountNumber; // integer account number
double balance = 0.0; // account balance
double amount; // adjusted amount to balance
String balanceFmt = "%.2f"; // string format for 2 decimal places
public BankAccount(String owner, int accountNumber) { //Constructor for the bank account
this.owner = owner;
this.accountNumber = accountNumber;
}
public double adjust(double amount) { //method to adjust balance
this.balance += amount;
return balance;
}
public String toString() { // method to print out account info
return owner + " owns the account " + accountNumber + " with the balance of $" + String.format(balanceFmt,balance);
}
public double getBalance() { // method to get balance of accounts
return balance;
}
}
银行类
public class Bank {
BankAccount bank[];
public Bank() { // constructor for making a 10 account array
bank = new BankAccount[10];
}
public void addAccount(BankAccount accounts) { // add account for giving numbers to accounts
for(int i = 0; i < bank.length; i++) {
if(bank[i] == null) {
bank[i] = accounts;
break;
}
}
}
BankAccount getAccount(int i) { //obtain account from BankAccount class
return bank[i];
}
慕仙森
MM们
相关分类