Advertisement
Guest User

sss

a guest
Apr 22nd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.84 KB | None | 0 0
  1. public static void main(String[] arguments) throws DuplicateProductException {
  2.  
  3. Restaurant restoran = new Restaurant("Restaurant");
  4.  
  5. SimpleProduct simple1=new SimpleProduct("simple1", 1f);
  6. SimpleProduct simple2=new SimpleProduct("simple2", 2f);
  7. SimpleProduct simple3=new SimpleProduct("simple3", 3f);
  8. SimpleProduct simple4=new SimpleProduct("simple4", 4f);
  9. SimpleProduct simple5=new SimpleProduct("simple5", 5f);
  10.  
  11. ExtendedProduct extended1=new ExtendedProduct("extended 1",11f);
  12. ExtendedProduct extended2=new ExtendedProduct("extended 2",12f);
  13. ExtendedProduct extended3=new ExtendedProduct("extended 3",13f);
  14. ExtendedProduct extended4=new ExtendedProduct("extended 4",14f);
  15. ExtendedProduct extended5=new ExtendedProduct("extended 5",15f);
  16.  
  17. CompositeProduct composite1 = new CompositeProduct("composite 1",1f);
  18. composite1.addProduct(simple1);
  19.  
  20. CompositeProduct composite2 = new CompositeProduct("composite 2",2f);
  21. composite2.addProduct(extended1);
  22.  
  23. CompositeProduct composite3 = new CompositeProduct("composite 3",3f);
  24. composite3.addProduct(composite2);
  25.  
  26. CompositeProduct composite4 = new CompositeProduct("composite 4",4f);
  27. composite4.addProduct(composite1);
  28.  
  29. restoran.addProduct(simple1);
  30. restoran.addProduct(simple2);
  31. restoran.addProduct(simple3);
  32. restoran.addProduct(simple4);
  33. restoran.addProduct(simple5);
  34. restoran.addProduct(extended1);
  35. restoran.addProduct(extended2);
  36. restoran.addProduct(extended3);
  37. restoran.addProduct(extended4);
  38. restoran.addProduct(extended5);
  39. restoran.addProduct(composite1);
  40. restoran.addProduct(composite2);
  41. restoran.addProduct(composite3);
  42. restoran.addProduct(composite4);
  43.  
  44. //restoran.addProduct(simple2); //duplicate
  45.  
  46. Table table1= new Table("table 1");
  47. Table table2= new Table("table 2");
  48. Table table3= new Table("table 3");
  49.  
  50. restoran.CreateTable("table 1");
  51. restoran.CreateTable("table 2");
  52. restoran.CreateTable("table 3");
  53.  
  54. restoran.orderProductForTable(table1,simple1);
  55. restoran.orderProductForTable(table1, simple2, 2);
  56.  
  57. restoran.orderProductForTable(table2,extended2,3);
  58. restoran.orderProductForTable(table2, composite3);
  59.  
  60. restoran.orderProductForTable(table3, composite1);
  61. restoran.orderProductForTable(table3, extended4, 4);
  62.  
  63. System.out.println(restoran.toString());
  64.  
  65. if(restoran.findProduct("simple1") != null)
  66. {
  67. System.out.println("Product named '" +"' exists.");
  68. }
  69. boolean choice=true;
  70. Scanner input = new Scanner(System.in);
  71. while(choice)
  72. {
  73. int c = 0;
  74.  
  75. System.out.println("1 <--- Search");
  76. System.out.println("2 <-- Add");
  77.  
  78. c = input.nextInt();
  79. switch(c)
  80. {
  81. case 1:
  82. {
  83. System.out.println("Choose name: ");
  84. String str = input.next();
  85. if(restoran.findProduct(str) != null)
  86. {
  87. System.out.println("Product named '" + str + "' exists.");
  88. }else
  89. {
  90. System.out.println("Product named '" + str + "' doesn't exist.");
  91. }
  92. break;
  93. }
  94. case 2:
  95. {
  96. System.out.println("Choose name: ");
  97. String str = input.next();
  98. System.out.println("Choose price: ");
  99. float cost = input.nextFloat();
  100. try
  101. {
  102. restoran.addProduct(new SimpleProduct(str, cost));
  103. }catch(DuplicateProductException ex)
  104. {
  105. System.out.println(ex.getMessage());
  106. }
  107. break;
  108. }
  109. }
  110. }
  111. input.close();
  112. }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement