Write a java programm that calculates the total of a retail sale should ask the
ID: 3671222 • Letter: W
Question
Write a java programm that calculates the total of a retail sale should ask the user for the following: The retail price of the item being purchased The sales tax rate Once these items have been entered, the program should calculate and display the following: The sales tax for the purchase The total of the sale I tried doing it here. but it is not giving me the right answer. kindly help correct the errors.
import java.util.Scanner; public class SalesTax { public static void main(String[] args)
{ //identifier declarations int TAX_RATE = 825;//8.25%
int price; String item;
//create a Scanner object to read from the keyboard Scanner keyboard = new Scanner(System.in);
//prompt and get input System.out.print("Item description: ");
item = keyboard.nextLine();
System.out.print("Item price: $"); price = keyboard.nextprice();
//calculations tax = price + (TAX_RATE/100);
total = price + tax; //display results System.out.print(item + " $");
System.out.println(price);
System.out.print("Tax $");
System.out.println(tax);
System.out.print("Total $");
System.out.println(total);
}
}
Explanation / Answer
import java.util.Scanner;
public class SalesTax {
public static void main(String[] args) {
// identifier declarations
// int TAX_RATE = 825;//8.25%
int price;
String item;
// create a Scanner object to read from the keyboard
Scanner keyboard = new Scanner(System.in);
// prompt and get input
System.out.print("Enter Item description: ");
item = keyboard.nextLine();
System.out.print("Enter Item price: $");
price = keyboard.nextInt();
System.out.print("Enter Tax rate: $");
double TAX_RATE = keyboard.nextDouble();
// calculations
double tax = price * (TAX_RATE / 100);
double total = price + tax;
// display results
System.out.print("Details : " + item + " $");
System.out.println(price);
System.out.print("Tax $");
System.out.println(tax);
System.out.print("Total $");
System.out.println(total);
}
}
OUTPUT:
Enter Item description: Coco
Enter Item price: $120
Enter Tax rate: $8.25
Details :
Coco $120
Tax $9.9
Total $129.9
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.