Question: I have a basic code below. Please add new method and change it but have to follow the below code to: Rounds up or down

I have a basic code below. Please add new method and change it but have to follow the below code to:

Rounds up or down

and Throws Bad Change Exception

public class MakeChange { // main method public static void main(String[] args) { // Creating the instance of the Scanner class Scanner input = new Scanner(System.in);

// Prompting user for asking the positive integer less than 100 System.out.print("Enter the positive integer (less than 100): ");

// Getting the user input int coins = input.nextInt();

// Checking whether the input is less than 100 or not if (coins < 100 && coins > 0){ // If it is less than 100 then // Calculating the quarters int quarters = coins / 25;

// Calculating the dimes int dimes = (coins - quarters*25) / 10;

// Calculating the nickels int nickels = (coins - quarters*25 - dimes*10) / 5;

// Calculating the cents int cents = coins - quarters*25 - dimes*10 - nickels*5;

// Displaying the output onto the console System.out.println(" " + coins + " cents: " + quarters + " quarters, " + dimes + " dimes, " + nickels +" nickels, " + cents + " cent"); } else{ // If it is not less than 100 then displaying the error message System.out.println(" Invalid input!!"); } } }

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!