Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Develop a Java program that will calculate the change in dollars, quarters, dimes, nickels, and pennies for a dollar bill tendered when purchasing an item.

Develop a Java program that will calculate the change in dollars, quarters, dimes, nickels, and pennies for a dollar bill tendered when purchasing an item.

For example: An item costs 7.26. The customer hands out a 10-dollar bill. The change is: $2.74 broken down as follows:

dollars: 2

quarters: 2

dimes: 2

nickels: 0

pennies: 4

Specifications:

1. Prompt the user to enter the following from the keyboard:

- Item amount

- Dollar bill tendered

2. For this exercise, assume that the user will ONLY enter a 10, 20, or 50 dollar bill.

3. The Java program will produce the following example output:

Dollar bill: 10.0 Item amount: 7.26

Change given: 2.74

dollars: 2

quarters: 2

dimes: 2

nickels: 0

pennies: 4

Your program MUST follow the above output format.

4. Calculation hints:

Here's an example that shows how to obtain the whole number value of a floating point number:

double change = 10.0 7.26; // change will be assigned the value 2.74

int numDollars = (int)change; // will assign 2 to numDollars

6. Submit the following:

- show your source code

- Show the output

- Flow chart /Pseudo code

This is the code:

// Fig. 2.7: Addition.java

// Addition program that displays the sum of two numbers. import java.util.Scanner; // program uses class Scanner

public class Addition { // main method begins execution of Java application public static void main( String[] args ) { // create a Scanner to obtain input from the command window Scanner input = new Scanner( System.in );

int number1; // first number to add int number2; // second number to add int sum; // sum of number1 and number2

System.out.print( "Enter first integer: " ); // prompt number1 = input.nextInt(); // read first number from user

System.out.print( "Enter second integer: " ); // prompt number2 = input.nextInt(); // read second number from user

sum = number1 + number2; // add numbers, then store total in sum

System.out.printf( "Sum is %d ", sum ); // display sum } // end method main }

Please answer all the questions

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

blur-text-image

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

Learning PostgreSQL

Authors: Salahaldin Juba, Achim Vannahme, Andrey Volkov

1st Edition

178398919X, 9781783989195

More Books

Students also viewed these Databases questions

Question

Explain what the DuPont financial system tries to reveal.

Answered: 1 week ago

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago