Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need a coin removal function written in java that can take a price and a bank

ID: 3591685 • Letter: I

Question

I need a coin removal function written in java that can take a price and a bank with values for quarters, dimes, nickels, and pennies and determine what coins are available to pay for an item and deduct them from the balance. function declared like public void removeCoins(Bank currentBank, float price) price is price of object that is being paid for via bank in format of float ie $2.50 would be 2.5f currentBank has currentBank.quarters, currentBank.dimes, currentBank.nickels, currentBank.pennies. This is a literal count of the number of quarters, dimes, etc..

Please only make the coin removal function, the rest of the program is already written. All I need is a function to calculate the transaction. This should be possible with just the number of each coin and the price of the item.

Explanation / Answer

public void removeCoins(Bank currentBank, float price) {

//convert price to cents first

int price_cents = Math.round(price*100);

// get quarters

currentBank.quarters = currentBank.quarters - (int)(price_cents/25);

price_cents %= 25;

// get dimes

currentBank.dimes = (int)(price_cents/10);

price_cents %= 10;

// get nickels

currentBank.nickels = (int)(price_cents/5);

price_cents %= 5;

// get pennies

currentBank.pennies = (int)(price_cents/1);

price_cents %= 1;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote