hi how to use if, if else,for,while,do wile ad switch in same class? very urgent..
import java.util.*; import java.text.*; class Shop{ public String item; public int quantity; public double price; public double discount; public double total; public Shop(){} public Shop(String item,int quantity, double price,double discount,double total) { super(); this.item=item; this.quantity= quantity; this.price = price; this.discount=discount; this.total=total; } public String getItem() { return item; } public int getQuantity() { return quantity; } public double getPrice() { return price; } public double getDiscount() { return discount; } public double getTotal() { return total; } public static void main(String[] args) throws Exception { double sum=0.0; DecimalFormat df = new DecimalFormat("##%"); List<Shop> list = new ArrayList<Shop>(); Scanner scan = new Scanner(System.in); int menu = 0; System.out.println("Cloth Showroom"); System.out.println(); System.out.println("1. T Shirt"); System.out.println("2. Silk sari"); System.out.println("3. Baba suit"); System.out.println("4. Trousers "); System.out.println("5. Exit"); boolean quit = false; do{ System.out.print("Please enter your choice: "); menu = scan.nextInt(); System.out.println(); switch(menu) { case 1: System.out.print("Quantity: "); int q1 = scan.nextInt(); System.out.print("Price: "); double p1 = scan.nextDouble(); double d1=0.10; double t1=(p1-(d1*p1))*q1; list.add(new Shop("T Shirt",q1,p1,d1,t1)); break; case 2: System.out.print("Quantity: "); int q2 = scan.nextInt(); System.out.print("Price: "); double p2 = scan.nextDouble(); double d2=0.30; double t2=(p2-(d2*p2))*q2; list.add(new Shop("Silk sari",q2,p2,d2,t2)); break; case 3: System.out.print("Quantity: "); int q3 = scan.nextInt(); System.out.print("Price: "); double p3 = scan.nextDouble(); double d3=0.40; double t3=(p3-(d3*p3))*q3; list.add(new Shop("Baba suit",q3,p3,d3,t3)); break; case 4: System.out.print("Quantity: "); int q4 = scan.nextInt(); System.out.print("Price: "); double p4 = scan.nextDouble(); double d4=0.15; double t4=(p4-(d4*p4))*q4; list.add(new Shop("Trousers",q4,p4,d4,t4));break; case 5: quit = true; System.out.println("Items Quantity Price T.Price Discount(%) Total"); for (Shop s : list){ System.out.println(s.getItem()+" " +s.getQuantity()+" "+s.getPrice()+" "+(s.getQuantity()*s.getPrice())+" " +df.format((s.getDiscount()))+" " +s.getTotal()); sum+=s.getTotal(); } System.out.println("Total= "+sum); break; default: System.out.println("Invalid Entry!"); } } while (!quit); } }
Please visit the following link: