Siddhant SA3 - Java Programming
unknown
java
a year ago
1.9 kB
3
Indexable
public class Items { String name; double price; Items() { name = ""; price = 0; } public Items(String name, double price) { this.name = name; this.price = price; } void printBill(Items[] items) { double subTotal = 0; double total = 0; for (int i = 0; i < items.length; i++) { subTotal += items[i].price; } System.out.println(" BILL "); System.out.println("Item Name\t\tPrice"); System.out.println("--------------------------------------------"); for (int i = 0; i < items.length; i++) { System.out.printf("%-20s \t\t%8.2f\n", items[i].name, items[i].price); } if (subTotal < 2000) { total = subTotal; System.out.printf("Final Amount\t\t$%.2f\n", total); }else { total = subTotal * 0.75; System.out.println("Eligible for 25% discout"); System.out.println("--------------------------------------------"); System.out.printf("Before Discount\t\t\t$%.2f\n", subTotal); System.out.printf("Discount (25%%)\t\t\t$%.2f\n", subTotal*0.25); System.out.println("--------------------------------------------"); System.out.printf("Final Amount\t\t\t$%.2f\n", total); } } public static void main(String[] args) { Items[] items = { new Items("Amul Cheese", 500), new Items("Ferrero Rochers", 1500), new Items("Pringles Classic", 120), new Items("Nutella", 600), new Items("Duracell Batteries", 200) }; Items bill = new Items("Bill", 0); bill.printBill(items); } }
Editor is loading...
Leave a Comment