1. You have been asked to write an invoice application which calculates the tota
ID: 3753023 • Letter: 1
Question
1. You have been asked to write an invoice application which calculates the total sales amount (including sales tax) for a sales transaction, and then prints the result. Declare variables (of an appropriate type and using meaningful variable names) to represent The name of the purchased Item. The cost for each individual unit. The number of units purchased. . The tax rate Assign sample data to the variables, and use this information to calculate the total sales amount. The program should output an invoice with all the appropriate information for the sale. For example, if your sample data consisted of purchasing 6 Bananas at $0.50 each with a tax rate of 10%, the output of your program might be the following invoice: SUNY Orange Fruit Co. Sales Invoice Item QuantityUnit Price Subtotal TaxTotal Bananas 6 0.50 3.00 0.30 3.30 Thank you for shopping with the SUNY Orange Fruit Co. Make sure you write a complete Java programExplanation / Answer
Item.java
import java.util.Scanner;
public class Item {
public static void main(String[] args) {
//Declaring variables
String name;
double cost,taxRate,subTot,tax,tot;
int noOfUnits;
/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
Scanner sc = new Scanner(System.in);
//Getting the input entered by the user
System.out.print("Enter Item Name:");
name=sc.nextLine();
System.out.print("Enter Cost of individual Item:");
cost=sc.nextDouble();
System.out.print("Enter no of units purchased:");
noOfUnits=sc.nextInt();
System.out.print("Enter Tax Rate:");
taxRate=sc.nextDouble();
//calculations
subTot=noOfUnits*cost;
tax=subTot*(taxRate/100);
tot=subTot+tax;
//Displaying the output
System.out.println(" SUNNY Orange Fruit Co.");
System.out.println("Sales Invoice");
System.out.println(" Item Quantity Unit Price SubTotal Tax Total");
System.out.printf("%s %d %.2f %.2f %.2f %.2f ",name,noOfUnits,cost,subTot,tax,tot);
}
}
_________________
Output:
Enter Item Name:Banana
Enter Cost of individual Item:0.50
Enter no of units purchased:6
Enter Tax Rate:10
SUNNY Orange Fruit Co.
Sales Invoice
Item Quantity Unit Price SubTotal Tax Total
Banana 6 0.50 3.00 0.30 3.30
_______Could you plz rate me well.Thank You
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.