Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8633167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:27:09+00:00 2026-06-12T09:27:09+00:00

So, I have this problem that I’ve been working on where the goal is

  • 0

So, I have this problem that I’ve been working on where the goal is to deduct a fee for each transaction in a bank account that goes over the allotted number of free transactions. So far I’ve got everything in place to count the transactions, but we’re supposed to be working with Math.max to make it so that when you go over the free transaction amount, the fees start getting subtracted from the balance of the account. I’m using the Math.max in my deductMonthlyCharge method. I think I know how to do this with if and else statements, but we’re not allowed to use them here and I’m not very familiar with Math.max. So, if anyone could point me in the right direction to figure this out, that would be great. Thanks.

/**
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;
}
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:27:10+00:00Added an answer on June 12, 2026 at 9:27 am

    I think you want something like this (which assumes a fee of $1.00 for each transaction over the allowed amount):

    public double deductMonthlyCharge()
    {
        int transCount = Math.max(transactionCount, freeTransactions);
        double fee = 1.00 * (transCount - freeTransactions);
        return fee;
    }
    

    If the customer hasn’t gone over their allowed number of free transactions, then (transCount - freeTransactions) will be 0, so no fee will be charged.

    This code is a little too clever for its own good, but I think it’s what the eccentric requirement (don’t use an if statement, use max instead) calls for.

    Much clearer (but equivalent) would be:

    public double deductMonthlyCharge()
    {
        if (transactionCount > freeTransactions) {
            return 1.00 * (transactionCount - freeTransactions);
        }
        return 0.0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a problem that uses pointer arithmetic and I have found this
I have this problem that when there is an OpenGL application I am working
Hello all I have this problem that I can't seem to fix. I've been
I'm working on this little enrollment system and i have this problem that if
i have this problem that has been buggin me for the last hours. Lets
I have this problem that I can ref a button for control it. I
I have this problem that my sites uses alot of ajax and when a
Ok I have this problem that I've never had before, it's really bugging me.
So we have this problem that we are trying to figure out. Heres what
I have this problem decomposing a relation schema into a set of schemas that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.