Question

In: Computer Science

In Java: Implement a program that directs a cashier how to give change. The program has...

In Java:

Implement a program that directs a cashier how to give change. The program has two inputs: the amount due and the amount received from the customer.

Display the dollars, quarters, dimes, nickels, and pennies that the customer should receive in return. In order to avoid roundoff errors, the program user should supply both amounts in pennies (for example 274 instead of 2.74).

Solutions

Expert Solution

Solution:-

import java.util.Scanner;

public class makingChange

{

public static void main(String[] args)

{

Scanner scan=new Scanner(System.in);

double amt;

int ten,five,one,quarter,dime,nickel,totalCents;

double amtdue,amtpaid;

System.out.println("Please enter the amount due :");

amtdue=scan.nextDouble();

System.out.println("Please enter the amount paid :");

amtpaid=scan.nextDouble();

amt=amtpaid-amtdue;

totalCents=(int)amt;

totalCents= (int) (100*amt);

ten=(totalCents/1000);

five=(int) ((amt-(ten*10))/5); //(totalCents/500);

one=(int) ((amt-(ten*10)-(five*5))/1);

quarter=(int) ((amt-(ten*10)-(five*5)-(one*1))/.25);

dime=(int) ((amt-(ten*10)-(five*5)-(one*1)-(quarter*.25))/.10);

nickel=(int) ((amt-(ten*10)-(five*5)-(one*1)-(quarter*.25)-(dime*.10))/.05);

System.out.println("Ten dollar bills: " + ten);

System.out.println("Five dollar bills: " + five);

System.out.println("One dollar bills: " + one);

System.out.println("Quarters: " + quarter);

System.out.println("Dimes: " + dime);

System.out.println("Nickels: " + nickel);

}

}

Thanking you.


Related Solutions

Using C++ Giving change. Implement a program that directs a cashier how to give change. The...
Using C++ Giving change. Implement a program that directs a cashier how to give change. The program has two inputs: the amount due and the amount received from the customer. Compute the difference, and compute the dollars, quarters, dimes, nickels, and pennies that the customer should receive in return.
Write a Java program that directs the user to enter a single word (of at least...
Write a Java program that directs the user to enter a single word (of at least four characters in length) as input and then prints the word out in reverse in the pattern shown below (please note that the spaces added between each letter are important and should be part of the program you write): <Sample Output Enter a word (at least four characters in length): cat Word must be at least four characters in length, please try again. Enter...
Write a program in Java Design and implement simple matrix manipulation techniques program in java. Project...
Write a program in Java Design and implement simple matrix manipulation techniques program in java. Project Details: Your program should use 2D arrays to implement simple matrix operations. Your program should do the following: • Read the number of rows and columns of a matrix M1 from the user. Use an input validation loop to make sure the values are greater than 0. • Read the elements of M1 in row major order • Print M1 to the console; make...
Java-- For this homework you are required to implement a change calculator that will provide the...
Java-- For this homework you are required to implement a change calculator that will provide the change in the least amount of bills/coins. The application needs to start by asking the user about the purchase amount and the paid amount and then display the change as follows: Supposing the purchase amount is $4.34 and the paid amount is $20, the change should be: 1 x $10 bill 1 x $5 bill 2 x Quarter coin 1 x Dime coin 1...
A cinema has a single ticket counter that is manned by a cashier. The cashier is...
A cinema has a single ticket counter that is manned by a cashier. The cashier is capable to handle 280 customers in an hour. Customers arrive at the counter at the rate of four customers per minute. Daniel, the owner who studied queuing models feels that all the seven assumptions for a single-channel model are met. By assuming Exponential service times and Poisson arrival rate, answer the following questions. a) State three assumptions mentioned above. b) Determine the average number...
Design and implement a Java program that creates a GUI that will allow a customer to...
Design and implement a Java program that creates a GUI that will allow a customer to order pizza and other items from a Pizza Paarlor. The customer should be able to order a variety of items which are listed below. The GUI should allow the customer (viaJavaFX UI Controls - text areas, buttons, checkbox, radio button, etc.) to input the following information: Name of the customer First Name Last Name Phone number of the customer Type of food being order...
In java, implement a program that returns a value of the area of the geometric objects...
In java, implement a program that returns a value of the area of the geometric objects listed below. Use the technique of method overloading concept and also uses the interfaces for dynamic method invocation. Triangle: √?(? − ?)(? − ?)(? − ?) where s=(a+b+c)/2 a,b,c are the sides of the triangle. Square: A^2 where A is the side Rectangle: (a*b) where a ,b are sides Circle: ? = ??2 where r is the radius Cube: 6a^2 where a is the...
Bank Accounts in Java! Design and implement a Java program that does the following: 1) reads...
Bank Accounts in Java! Design and implement a Java program that does the following: 1) reads in the principle 2) reads in additional money deposited each year (treat this as a constant) 3) reads in years to grow, and 4) reads in interest rate And then finally prints out how much money they would have each year. See below for formatting. Enter the principle: XX Enter the annual addition: XX Enter the number of years to grow: XX Enter the...
Please show solution and comments for this data structure using java.​ Implement a program in Java...
Please show solution and comments for this data structure using java.​ Implement a program in Java to convert an infix expression that includes (, ), +, -, *,     and / to postfix expression. For simplicity, your program will read from standard input (until the user enters the symbol “=”) an infix expression of single lower case and the operators +, -, /, *, and ( ), and output a postfix expression.
4 Implement a Java program that meets the following requirements • You can use the Java...
4 Implement a Java program that meets the following requirements • You can use the Java standard sequence data structure API types for sets, lists, stack,queue and priority queue as needed. All are available in the java.util package, which you will want to import in your program. 1. Argue in code comments which data structure, stack or queue, you will use to implement this method. Implement a method which creates some String objects as food orders for a small restaurant,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT