Guest User

Untitled

a guest
Nov 16th, 2015
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. public class Shop
  2. {
  3. public static void main(String [] args)
  4. {
  5. ProductList basket = new ProductList();
  6. ProductList beverages = new ProductList();
  7. Scanner optionScanner = new Scanner(System.in);
  8. int option = 0;
  9.  
  10. beverages.addProduct(new Product("Coffe", 3));
  11. beverages.addProduct(new Product("Tea", 1));
  12. beverages.addProduct(new Product("Soup", 1.5));
  13. beverages.addProduct(new Product("Water", 2));
  14.  
  15. System.out.println("Press number for : ");
  16. beverages.printListWithIndex();
  17. System.out.println(beverages.size() + ". Finish to pay");
  18. System.out.print("Option :");
  19.  
  20. option = optionScanner.nextInt();
  21.  
  22. while(option != beverages.size())
  23. {
  24. try
  25. {
  26. basket.addProduct(beverages.get(option));
  27. }
  28. catch(IndexOutOfBoundsException e)
  29. {
  30. System.out.println("Wrong index");
  31. }
  32. option = optionScanner.nextInt();
  33. }
  34.  
  35. System.out.println("You have bought: " );
  36. basket.printList();
  37. System.out.println("Number of items: " + basket.size());
  38. System.out.println("Sum: " + basket.getTotalPrice());
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment