# Write a program in Java that prompts the user for the number of pennies, nickels, dimes and quarters (4 different prompts). Output what the total dollar value would be when all are added up. in Project template

Question
50 views

Write a program in Java that prompts the user for the number of pennies, nickels, dimes and quarters (4 different prompts). Output what the total dollar value would be when all are added up. in Project template

check_circle

Step 1

A Java program is to be written that would take the values of pennies, nickels, dimes and quarters and will produce the output with the sum of all the four values in dollar. The values for pennies, nickels, dimes and quarters are entered by the users so scanner class would be used.

Step 2

The Java program is given below:

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

int quarters;   //  quarters value to be input by the user.

int dimes;      //  dimes value to be input by the user.

int nickels;    //  nickels value to be input by the user.

int pennies;    // pennies value to be input by the user.

Scanner val = new Scanner( System.in );

double totalDollars; // Total value in dollars.

/* Inputting number of each type of coin by user. */

System.out.print("Number of quarters: ");

quarters = val.nextInt();

val.nextLine();

System.out.print("Number of dimes: ");

dimes = val.nextInt();

val.nextLine();

System.out.print("Number of nickels: ");

nickels = val.nextInt();

val.nextLine();

System.out.print("Number of pennies: ");

pennies = val.nextInt();

val.nextLine();

/* values of the coins are added and are converted in dollars. */

totalDollars = (0.25 * quarters) + (0.10 * dimes)

+ (0.05 * nickels) + (0.01 * pennies);

/* Displaying the result to user. */

System.out.print("The total of all in dollars is \$");

System.out.printf("%1.2f", totalDollars);  // output formatting

}

}

Step 3

The above program is taking the input values for number of pennies, nickels, dimes and quarters from the user. Then conversi...

### Want to see the full answer?

See Solution

#### Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

### Object Oriented Programming 