그래서, 할당 된 무료 거래 횟수를 초과하는 은행 계좌에서 각 거래에 대한 수수료를 공제하는 것이 목표 인 곳에서이 문제를 겪고 있습니다. 지금까지 거래를 계산할 수있는 모든 것을 갖추고 있었지만 Math.max와 협력하여 무료 거래 금액을 초과 할 경우 수수료가 잔액에서 제외되기 시작했습니다. 계정. 내 deductMonthlyCharge 메소드에서 Math.max를 사용하고 있습니다. 나는 if와 else 문으로이 작업을 수행하는 방법을 알고 있다고 생각합니다.하지만 여기서는 사용할 수 없으며 Math.max에 익숙하지 않습니다. 그래서 누군가가 올바른 방향으로 이것을 지적 해 주면 좋을 것입니다. 감사.은행 계좌 거래를위한 Java 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;
}
}
는 당신이 바로'Math.max()가'값을 반환 실현? 당신이 통과 한 어떤 것도 바꿀 수는 없습니다. – NullUserException
돈을 생성하거나 버려서는 안됩니다. 돈은 주변을 옮겨야합니다. –