how to insert the description in java and how to run like this in string or if else statement please help me here is my image and my code
System.out.println("Welcome to the Line Item Calculator");
System.out.println();
Scanner sc = new Scanner(System.in);
String choice = "y";
while (choice.equalsIgnoreCase("y")) {
// get input from user
System.out.print("Enter product code: ");
String productCode = sc.nextLine();
// String productdes = sc.equals();
System.out.print("Enter quantity: ");
int quantity = Integer.parseInt(sc.nextLine());
// set product price based on product code
double price;
if (productCode.equalsIgnoreCase("java")) {
price = 57.50;
} else if (productCode.equalsIgnoreCase("jsp")) {
price = 57.50;
} else if (productCode.equalsIgnoreCase("mysql")) {
price = 54.50;
} else {
price = 0;
}
// calculate total
double total = price * quantity;
// format and display output
NumberFormat currency = NumberFormat.getCurrencyInstance();
String priceFormatted = currency.format(price);
String totalFormatted = currency.format(total);
String message = "\nLINE ITEM\n" +
"Code: " + productCode + "\n" +
"Price: " + priceFormatted + "\n" +
"Quantity: " + quantity + "\n" +
"Total: " + totalFormatted + "\n";
System.out.println(message);
// see if the user wants to continue
System.out.print("Continue? (y/n): ");
choice = sc.nextLine();
System.out.println();
}
Aucun commentaire:
Enregistrer un commentaire