Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!