Making use of object orientation write a program that stores and evaluates the total cost for items bought from a supermarket. The cashier should enter the following: - Product code, Price and Quantity. The total price should be evaluated as follows: -
Total cost = Price * Quantity
If the total cost per item is more than 20,000 there is a discount of 14% on that item and a discount of 10% on an item whose total cost is between 10,000 and 20,000. No discount is given on items whose total cost is less than 10,000
import java.util.*;
class App {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter the product code: ");
String code = keyboard.nextLine();
// Product code, Price and Quantity.
System.out.print("Enter the product price: ");
double price = keyboard.nextDouble();
System.out.print("Enter the product quantity: ");
int quantity = keyboard.nextInt();
double totalCost = price * quantity;
double discount = 0;
if (totalCost >= 20000) {
discount = totalCost * 0.14;
} else if (totalCost >= 10000 && totalCost < 20000) {
discount = totalCost * 0.1;
}
System.out.println("The product code: " + code);
System.out.println("The product total cost: " + totalCost);
System.out.println("The discount: " + discount);
totalCost -= discount;
System.out.println("The total cost: " + totalCost);
keyboard.close();
}
}
Comments
Leave a comment