You are required to write a Java program for a company that sells items of hardware over the internet. Your program will list all the available hardware with their corresponding prices for the customer to select. Your customer needs to input the selected item and the quantity of that item. Your program should calculate the total price that the customer needs to pay. The total price must also be inclusive of a 3% tax. To make it easier for you, the company only sells 5 items, which you are given the freedom to choose what item to sell, and how much is the price. The program will keep on asking the customer to continue shopping until the customer decides to stop. At the end of the session, the total price must be displayed to the user. (This is the question)
package courseworkitpl;
import java.util.Scanner;
public class CourseworkITPL {
public static void main(String[] args) {
// TODO code application logic here
int choice,quantity;
double price,tax;
String answer;
int Macbook = 1;
int Dell = 2;
int ROG = 3;
int Alienware = 4;
int Razer = 5;
int MacbookCost = 300;
int DellCost = 250;
int ROGCost = 395;
int AlienwareCost = 400;
int RazerCost = 350;
tax=0.03;
Scanner keyboard = new Scanner(System.in);
Double totalSum = 0d;
do{
System.out.println("Welcome to my store, which computer do you like to purchase?");
System.out.println("1. Macbook");
System.out.println("2. Dell");
System.out.println("3. ROG");
System.out.println("4. Alienware");
System.out.println("5. Razer");
choice = keyboard.nextInt();
System.out.println("How much quantity you want to purchase?");
quantity = keyboard.nextInt();
if (choice == 1) {
price = (MacbookCost*0.03+(MacbookCost*quantity));
} else if (choice == 2) {
price = (DellCost*0.03+(DellCost*quantity));
} else if (choice == 3) {
price = (ROGCost*0.03+(ROGCost*quantity));
}else if (choice == 4) {
price = (AlienwareCost*0.03+(AlienwareCost*quantity));
}else if (choice == 5) {
price = (RazerCost*0.03+(RazerCost*quantity));
}
else {
price = 0;
System.out.println("invalid choice");
}
totalSum = totalSum + price;
System.out.print("Do you want to continue yes/no?");
answer = keyboard.next();
} while(answer.equalsIgnoreCase("yes"));
System.out.println("That will be $" + totalSum + " with 3% of tax.");
}
}