Asked Oct 7, 2019

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


Expert Answer

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( );

      double totalDollars; // Total value in dollars.

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

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

      quarters = val.nextInt();


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

      dimes = val.nextInt();


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

      nickels = val.nextInt();


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

      pennies = val.nextInt();


      /* 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

Check out a sample Q&A here.

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


Computer Science

Object Oriented Programming

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A

Q: My C++ program is supposed to check if a string input is in descending order. When I try to run it, ...

A: The given C++ code has few logical errors due to which it is not resulting the correct output. Revis...


Q: What is a hot spot and what are the benefits and cons?

A: Hotspot:A physical location that can obtain an internet access using Wireless Fidelity (Wi-Fi) is ca...


Q: Decisions about hardware focus on what 3 factors?

A: HardwareThe physical equipment which is used for input, processing, output and storage activities of...


Q: A company that wants to send data over the Internet has asked you to write a program that will encry...

A: Following code, take the user's four-digit number as input using main method then it will call the e...


Q: I am looking for help with how to read and understand where to start with this assignment.

A: High Level DesignFrom the limited information that has been provided here, here are the suggestions:...


Q: Using the following truth table, write the equivalent Boolean equations in Sum of Product and Produc...

A: Answer:Sum of Product (SOP) form:If the input is 1, then write an AND term for each input combinatio...


Q: Please put into SOP formxz + (xy + ~z)

A: A Boolean expression is said to be in the Canonical form either it has purely min-terms or max-terms...


Q: PLEASE EXPLAIN ALL STEPSDevelop a k-map to simplify the equation (truth table included)

A:  Given boolean expression = xz + (xy + ~z)Now by using given truth table, draw a K-map of 8 cells by...


Q: I've been struggling with understanding a question in my Python programming homework.I'm asked to co...

A: Following program takes input the distance in kilometers from user and uses the given conversion fac...