Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1.  
  2. // Name: SHENOUDA, ANTHONY 11-2-19
  3. // LAB 5 GRIGORIANTS, NATALIA T TH
  4. import java.util.Scanner;
  5.  
  6. public class LAB_5_SHENOUDA_ANTHONY {
  7. public static Inventory inventory = new Inventory();
  8. public static Scanner input = new Scanner(System.in);
  9.  
  10. public static void main(String[] args) {
  11. menu();// prompts the user to control the program
  12. }
  13.  
  14. /*
  15. * [menu]It goes to the method and assigns the numbers that are saved.
  16. * [menu post-condition] It returns what is saved and continues to each method.
  17. * It assigns the right topics to each method.
  18. */
  19.  
  20.  
  21. public static void menu() {
  22. {
  23. System.out.println("Menu:\n(1) Create new order\n" + "(2) Create new delivery\n" + "(3) Display Orders\n"
  24. + "(4) Display deliveries\n" + "(5) Display Widgets On Hand\n" + "(6) Quit\n");
  25.  
  26. Menu choice = Menu.fromId(input.nextInt());
  27. input.nextLine();
  28.  
  29. switch (choice) {
  30. case NEW_DELIVERY:
  31. inventory.addDelivery(createNewDelivery());
  32. System.out.println(String.format("\t%11s\t\t%10s\t\t %11s\t\t%10s","Qty On Hand", "Unit Price", "Cost To Warehouse", "Cost To Customer")); inventory.getDeliveries().forEach(d -> System.out.println(d));
  33. break;
  34. case NEW_ORDER:
  35. inventory.addOrder(createNewOrder());
  36. System.out.println(String.format("\t%11s\t\t%10s\t\t %11s\t\t%10s","Qty On Hand", "Unit Price", "Cost To Warehouse", "Cost To Customer")); inventory.getDeliveries().forEach(d -> System.out.println(d));
  37.  
  38. break;
  39. case DISPLAY_ORDERS:
  40. inventory.getOrders().forEach(o -> System.out.println(o));
  41. inventory.getFulfilledOrders().forEach(f -> System.out.println(f));
  42. System.out.println(String.format("\t%11s\t\t%10s\t\t %11s\t\t%10s","Qty On Hand", "Unit Price", "Cost To Warehouse", "Cost To Customer")); inventory.getDeliveries().forEach(d -> System.out.println(d));
  43. break;
  44. case DISPLAY_DELIVERIES:
  45. System.out.println(String.format("\t%11s\t\t%10s\t\t %11s\t\t%10s","Qty On Hand", "Unit Price", "Cost To Warehouse", "Cost To Customer")); inventory.getDeliveries().forEach(d -> System.out.println(d));
  46. break;
  47. case DISPLAY_WIDGETS_ON_HAND:
  48. System.out.println("Widgets on hand: " + inventory.getWidgetsOnHand());
  49. break;
  50. case QUIT:
  51. System.exit(0);
  52. default:
  53. System.out.println("Invalid menu option, try again");
  54. break;
  55. }
  56. menu();
  57.  
  58. }
  59. }
  60.  
  61. /*
  62. * [Delivery]It has the user to enter numbers
  63. * [Delivery post-condition] It saves the numbers typed in.
  64. * It asks price and widgets shipped and allows user to enter numbers.
  65. */
  66.  
  67. public static Delivery createNewDelivery() {
  68. System.out.print("Enter quantity of widgets shipped: ");
  69. int quantity = input.nextInt();
  70. while (quantity <= 0) {
  71. System.out.println("Negative Number entered, enter positive number: ");
  72. quantity = input.nextInt();
  73. }
  74. System.out.print("Enter unit price: ");
  75. double unitPrice = input.nextDouble();
  76. while (unitPrice <= 0.0) {
  77. System.out.println("Negative Number entered, enter positive number: ");
  78. unitPrice = input.nextDouble();
  79. }
  80. input.nextLine();
  81. return new Delivery(quantity, unitPrice);
  82. }
  83.  
  84. /*
  85. * [Order]It has the user to enter numbers
  86. * [Order post-condition] It saves the numbers typed in.
  87. * It asks quantity of widgets and allows user to enter numbers.
  88. */
  89.  
  90. public static Order createNewOrder() {
  91. System.out.print("Enter quantity of widgets to order: ");
  92. int quantity = input.nextInt();
  93. while (quantity <= 0) {
  94. System.out.println("Negative Number entered, enter positive number");
  95. quantity = input.nextInt();
  96. }
  97. input.nextLine();
  98. return new Order(quantity);
  99. }
  100.  
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement