Question

In: Computer Science

create a Java application program that will add up the cost of three items, then print...

create a Java application program that will add up the cost of three items, then print the final total with sales tax.

You should begin by prompting the user to enter three separate prices for three items that are being purchased. For each item you should ask for (in this order) the quantity of the product and the price of the product.

The program should compute, and be able to print to the screen:

the subtotal (the total amount due before tax)

sales tax (the amount of sales tax that will be added, assume 7% tax rate)

total due (subtotal + sales tax)

The following is an example of what your MIGHT see on the screen when your program runs. The exact output depends on what values that the user types in while the program runs. The user's values are shown below in italics:

Enter the quantity of the first product: 3
Enter the price of the first product: $5.25
Enter the quantity of the second product: 2
Enter the price of the second product: $1.83
Enter the quantity of the third product: 7
Enter the price of the third product: $0.89

Subtotal: $25.64
Sales Tax: $1.79
Total Due: $27.43

can post a screen shot of your java program Would like to learn the steps, i am doing intro to Java programing

Solutions

Expert Solution

CalCostofThreeItems.java

import java.text.DecimalFormat;
import java.util.Scanner;

public class CalCostofThreeItems {

   public static void main(String[] args) {

       //Declaring the variables
       int quant1,quant2,quant3;
       double price_prod1,price_prod2,price_prod3;
      
       //DecimalFormat class Object is used to Format the output values
       DecimalFormat df=new DecimalFormat("#.##");
      
       //Scanner object is used to get the inputs entered by the user
       Scanner sc=new Scanner(System.in);
         
       //Getting the quantity of first item entered by the user
       System.out.print("Enter the quantity of the first product:");
       quant1=sc.nextInt();
      
       //Getting the price of the first product entered by the user
       System.out.print("Enter the price of the first product: $");
       price_prod1=sc.nextDouble();
      
       //Getting the quantity of second item entered by the user
       System.out.print("Enter the quantity of the second product:");
       quant2=sc.nextInt();

       //Getting the price of the second product entered by the user
       System.out.print("Enter the price of the second product: $");
       price_prod2=sc.nextDouble();  
  
       //Getting the quantity of third item entered by the user
       System.out.print("Enter the quantity of the three product:");
       quant3=sc.nextInt();
      
       //Getting the price of the third product entered by the user
       System.out.print("Enter the price of the three product: $");
       price_prod3=sc.nextDouble();
      
       //Calculating the sub total
       double subTotal=quant1*price_prod1+quant2*price_prod2+quant3*price_prod3;
      
       //calculating the tax
       double tax=(subTotal*7/100);
      
       //calculating the total due
       double total_due=subTotal+tax;
      
       //Displaying the results
       System.out.println("\nSubtotal: $"+df.format(subTotal));
       System.out.println("Sales Tax: $"+df.format(tax));
       System.out.println("Total Due: $"+df.format(total_due));
      
   }

}

_________________

output:

Enter the quantity of the first product:3
Enter the price of the first product: $5.25
Enter the quantity of the second product:2
Enter the price of the second product: $1.83
Enter the quantity of the three product:7
Enter the price of the three product: $0.89

Subtotal: $25.64
Sales Tax: $1.79
Total Due: $27.43

_____________Thank You


Related Solutions

TO DO in JAVA: The program that runs is TrackInsurance. Open this up and add five...
TO DO in JAVA: The program that runs is TrackInsurance. Open this up and add five instances of your ArtInsurance class at the noted location in the main method. Use whatever data you like. TrackInsurance(below) package itp120mod6; import java.util.*; public class TrackInsurance extends Object { public static Scanner scan = new Scanner(System.in); // method that runs first public static void main(String[] args) throws Exception { // make an ArrayList of customers and insurance policies ArrayList cust = new ArrayList(); //...
Create a simple dice game in Java. Add screenshots and the program here.
Create a simple dice game in Java. Add screenshots and the program here.
Create a Java windows application to manage a list of stocks 1. Add a class Stock...
Create a Java windows application to manage a list of stocks 1. Add a class Stock with the following fields: companyName, pricePerShare, numberOfShares (currently owned) and commission (this is the percent you pay a financial company when you purchase or sell stocks. Add constructor, getters and methods: ***purchaseShares (method that takes the number of shares purchased, updates the stock and return the cost of purchasing these shares make sure to include commission. ***sellShares (method that takes the number of shares...
Write a Python program to (a) create a new empty stack. Then, (b) add items onto...
Write a Python program to (a) create a new empty stack. Then, (b) add items onto the stack. (c) Print the stack contents. (d) Remove an item off the stack, and (e) print the removed item. At the end, (f) print the new stack contents:
Create in java an interactive GUI application program that will prompt the user to use one...
Create in java an interactive GUI application program that will prompt the user to use one of three calculators, label project name MEDCALC. You can use any color you want for your background other than grey. Be sure to label main java box with “MEDCALC” and include text of “For use only by students” On all three calculators create an alert and signature area for each user. The alert should be something like “All calculations must be confirmed by user...
Create a JavaFX program in java that does the following items: Display a drawing area of...
Create a JavaFX program in java that does the following items: Display a drawing area of dimension 500 x 400, with a black background. Provides a radio button group to allow the user to select one of the following three colors: red, green, and blue. Upon startup, the red radio button should be selected. Each time the user clicks in the drawing area, a circle of size 10 of the color selected by the radio button group in item 2...
write a java program that takes three numbers from the user and print the greatest number...
write a java program that takes three numbers from the user and print the greatest number (using if-statement). sample output: input the first number:35 input the second number:28 input the third number:87 the greatest number:87
Create a Java application called ValidatePassword to validate a user’s password. Write a program that asks...
Create a Java application called ValidatePassword to validate a user’s password. Write a program that asks for a password, then asks again to confirm it. If the passwords don’t match or the rules are not fulfilled, prompt again. Your program should include a method that checks whether a password is valid. From that method, call a different method to validate the uppercase, lowercase, and digit requirements for a valid password. Your program should contain at least four methods in addition...
Create a java Swing GUI application that presents the user with a “fortune”. Create a java...
Create a java Swing GUI application that presents the user with a “fortune”. Create a java Swing GUI application in a new Netbeans project called FortuneTeller. Your project will have a FortuneTellerFrame.java class (which inherits from JFrame) and a java main class: FortuneTellerViewer.java. Your application should have and use the following components: Top panel: A JLabel with text “Fortune Teller” (or something similar!) and an ImageIcon. Find an appropriate non-commercial Fortune Teller image for your ImageIcon. (The JLabel has a...
Java Program 1Use a loop to add up the odd numbers between 100 and 200. 2Use...
Java Program 1Use a loop to add up the odd numbers between 100 and 200. 2Use a loop to determine if a number is prime. Recall: a number is prime if its only factors are 1 and itself. 3. Nested Loops: }Write a nested loop that finds the largest prime number smaller than 125.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT