Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Edit the given code by following these steps: All of the code continues to exist in one file. No attributes are listed as static. Use

Edit the given code by following these steps:

  1. All of the code continues to exist in one file.
  2. No attributes are listed as static.
  3. Use loops for any repetitive code
  4. There should be at least three methods in the class, all of which are called.
  5. Maintain the quality of the print ups (such as the handling of singular versus plural cases) or improve them; in other words, nothing should get worse with these changes

-Every method should be marked with an inline comment like the following that describes what it does, such as:

//---------------------------------------------------------------------- // calculates the airspeed velocity of an unladen swallow //----------------------------------------------------------------------

-Classes should begin with a capital letter while variables and methods should begin with lowercase letters. Variables and should have informative names, indicating what they represent. If a variable name or method is multiple words strung together, be sure to use capital letters to indicate subsequent words. For example, if a variable represents the mass of Mars, potential names for such a variable should be marsMass or massOfMars.

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

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

public class Coin{

// we'd like this to be one file // nonstatic attributes while still declaring in an attributes section // --you'll have to use other methods // utilize loops for anything repetitive // challenge: try to use as few variables as possible

//attributes public static Scanner userInput; public static int cents; public static NumberFormat dollarTotal;

//---------------------------------------------------------------------- // Main method: Received coin amounts and returns quantity with // bill/coin breakdown //---------------------------------------------------------------------- public static void main(String[] args){

//input for coins userInput = new Scanner(System.in);

// a loop -- for loop or while loop or do while loop ?? System.out.println("Enter the total number of quarters:"); cents = userInput.nextInt()*25;

System.out.println("Enter the total number of dimes:"); cents = cents + userInput.nextInt()*10;

System.out.println("Enter the total number of nickels:"); cents = cents + userInput.nextInt()*5;

System.out.println("Enter the total number of pennies:"); cents = cents + userInput.nextInt();

//total System.out.println("You have " + NumberFormat.getCurrencyInstance().format(cents / 100.00)); // Ref: // https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/text/NumberFormat.html // NumberFormat.getCurrencyInstance is a static method that formats a // numbers for specifically currency

// resulting bills & coins //$50 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"); }

cents = cents % 100; //update

//$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_2

Step: 3

blur-text-image_step3

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

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

ISBN: B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions