Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The code is completed, just edit by adding inline comments before each method describing what it does (space for the comment is given within the

The code is completed, just edit by adding inline comments before each method describing what it does (space for the comment is given within the dashes and forward slashes)

--------------------------------------------------------------------------

import java.util.Scanner; import java.text.NumberFormat;

public class Coin{ //---------------------------------------------------------------------- // Main method: Received coin amounts and returns quantity with // bill/coin breakdown //---------------------------------------------------------------------- public static void main(String[] args){ Scanner userInput = new Scanner(System.in); int cents=0;

cents=getUserInput(cents, userInput);

cents=printDollarBills(cents);

cents = cents % 100; //update

printCoinDetails(cents);

}

//---------------------------------------------------------------------- // // //----------------------------------------------------------------------

private static int getUserInput(int cents,Scanner userInput) { String[] coins= {"quarters","dimes","nickels","pennies"}; int[] multiFactor= {25,10,5,1}; // a loop -- for loop to get user data for(int i=0;i<4;i++) { System.out.println("Enter the total number of "+coins[i]); cents = cents+userInput.nextInt()*multiFactor[i]; } System.out.println("You have " + NumberFormat.getCurrencyInstance().format(cents / 100.00)); return cents; }

//---------------------------------------------------------------------- // // //----------------------------------------------------------------------

private static int printDollarBills(int cents) { if (cents/5000 > 1){ System.out.println(cents/5000 + " fifty dollar bills"); }else if(cents/5000 == 1){ System.out.println("1 fifty dollar bill"); }

cents = cents % 5000; //update

//$20 if (cents/2000 > 1){ System.out.println(cents/2000 + " twenty dollar bills"); }else if(cents/2000 == 1){ System.out.println("1 twenty dollar bill"); }

cents = cents % 2000; //update

//$10 if (cents/1000 == 1){ System.out.println("1 ten dollar bill"); }

cents = cents % 1000; //update

//$5 if (cents/500 == 1){ System.out.println("1 five dollar bill"); }

cents = cents % 500; //update

//$1 if (cents/100 > 1){ System.out.println(cents/100 + " one dollar bills"); }else if(cents/100 == 1){ System.out.println("1 one dollar bill"); }

return cents; }

//---------------------------------------------------------------------- // // //----------------------------------------------------------------------

private static void printCoinDetails(int cents) { //$0.25 if (cents/25 > 1){ System.out.println(cents/25 + " quarters"); }else if(cents/25 == 1){ System.out.println("1 quarter"); }

cents = cents % 25; //update

//$0.10 if (cents/10 > 1){ System.out.println(cents/10 + " dimes"); }else if(cents/10 == 1){ System.out.println("1 dime"); }

cents = cents % 10; //update

//$0.05 if (cents/5 == 1){ System.out.println(cents/5 + "1 nickel"); }

cents = cents % 5; //update

if (cents > 1){ System.out.println(cents + " pennies"); }else if(cents == 1){ System.out.println("1 penny"); } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 1 Lncs 13426

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124227, 978-3031124228

More Books

Students also viewed these Databases questions

Question

Question What is a Roth 403 (b) plan?

Answered: 1 week ago