Change Calculator Write a program that directs a cashier how to give change. The
ID: 3677307 • Letter: C
Question
Change Calculator Write 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. Print the following combination of stars using a for loop nested inside a for loop. Then a while loop nested inside a for loop. Each letter will have two separate programs that produce the same output. Attach Snipping photo of the source code for all 6 exercises and output.Explanation / Answer
Answer for Question 1:
This below program will print the dallers into it's denominations.
import java.util.*;
import java.text.DecimalFormat;
public class Money {
public static void main(String[] args){
//Variable and Constant Declaration
int price,amountpaid,dollars,quarters,dimes,nickels,change, pennies, remainder = 0;
Scanner sc = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("#0.0000");
//Input
System.out.println("Please enter the due in cents: ");
price = sc.nextInt();
System.out.println("Please enter the received in cents: ");
amountpaid = sc.nextInt();
//Calculations
remainder = price - amountpaid;
change = remainder;
dollars = remainder / 100;
remainder = remainder % 100;
quarters = remainder / 25;
remainder = remainder % 25;
dimes = remainder / 10;
remainder = remainder % 10;
nickels = remainder / 5;
remainder = remainder % 5;
pennies = remainder;
//Output
System.out.println("Purchase Price: $" + df.format((double)price/100) +
" Amount Tendered: $" + df.format((double)amountpaid/100) +
" Your Change is: $" + df.format((double)change/100) +
" " + dollars + " one-dollar bills(s) "
+ quarters + " quarter(s) " + dimes +
" dime(s) " + nickels + " nickle(s) " +
remainder + " penn(y/ies)");
System.out.println(" Thank you for your business. Come back soon.");
} // End Main
} //End Class
Answer for Question 3:
a)
class Pattern1
{
public static void main(String[] args)
{
int i, j;
for(i=5;i>=1;i--)
{
for(j=1;j<=i;j++)
{
System.out.print("*");
}
System.out.println();
}
}
}
b)
class Pattern2
{
public static void main(String[] args)
{
int i, j, k;
for(i=5;i>=1;i--)
{
for(j=1;j<i;j++)
{
System.out.print(" ");
}
for(k=5;k>=i;k--)
{
System.out.print("*");
}
System.out.println();
}
}
}
c)
class Pattern3
{
public static void main(String[] args)
{
int i, j, k;
for(i=10;i>=2;i--)
{
for(j=10;j>i;j--)
{
System.out.print(" ");
}
for(k=1;k<(i*2);k++)
{
System.out.print("*");
}
System.out.println();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.