そのため、私はこの問題を抱えており、銀行口座で割り当てられた無料トランザクション数を超えるトランザクションごとに手数料を差し引くことを目標に取り組んできました。これまでのところ、トランザクションをカウントするための準備はすべて整いましたが、Math.max を使用して、無料のトランザクション額を超えると、手数料が残高から差し引かれるようにすることになっています。アカウント。deductMonthlyCharge メソッドで Math.max を使用しています。if ステートメントと else ステートメントを使用してこれを行う方法は知っていると思いますが、ここでそれらを使用することは許可されておらず、Math.max にはあまり詳しくありません。したがって、誰かがこれを理解するために正しい方向に私を向けることができれば、それは素晴らしいことです. ありがとう。
/**
A bank account has a balance that can be changed by
deposits and withdrawals.
*/
public class BankAccount
{
private double balance;
private double fee;
private double freeTransactions;
private double transactionCount;
/**
Constructs a bank account with a zero balance
*/
public BankAccount()
{
balance = 0;
fee = 5;
freeTransactions = 5;
transactionCount = 0;
}
/**
Constructs a bank account with a given balance
@param initialBalance the initial balance
*/
public BankAccount(double initialBalance)
{
balance = initialBalance;
transactionCount = 0;
}
public static void main(String [ ] args)
{
BankAccount newTransaction = new BankAccount();
newTransaction.deposit(30);
newTransaction.withdraw(5);
newTransaction.deposit(20);
newTransaction.deposit(5);
newTransaction.withdraw(5);
newTransaction.deposit(10);
System.out.println(newTransaction.getBalance());
System.out.println(newTransaction.deductMonthlyCharge());
}
public void setTransFee(double amount)
{
balance = amount+(balance-fee);
balance = balance;
}
public void setNumFreeTrans(double amount)
{
amount = freeTransactions;
}
/**
Deposits money into the bank account.
@param amount the amount to deposit
*/
public void deposit(double amount)
{
double newBalance = balance + amount;
balance = newBalance;
transactionCount++;
}
/**
Withdraws money from the bank account.
@param amount the amount to withdraw
*/
public void withdraw(double amount)
{
double newBalance = balance - amount;
balance = newBalance;
transactionCount++;
}
public double deductMonthlyCharge()
{
Math.max(transactionCount, freeTransactions);
return transactionCount;
}
/**
Gets the current balance of the bank account.
@return the current balance
*/
public double getBalance()
{
return balance;
}
}