Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Name: SHENOUDA, ANTHONY 11-2-19
- // LAB 5 GRIGORIANTS, NATALIA T TH
- import java.util.Scanner;
- public class LAB_5_SHENOUDA_ANTHONY {
- public static Inventory inventory = new Inventory();
- public static Scanner input = new Scanner(System.in);
- public static void main(String[] args) {
- menu();// prompts the user to control the program
- }
- /*
- * [menu]It goes to the method and assigns the numbers that are saved.
- * [menu post-condition] It returns what is saved and continues to each method.
- * It assigns the right topics to each method.
- */
- public static void menu() {
- {
- System.out.println("Menu:\n(1) Create new order\n" + "(2) Create new delivery\n" + "(3) Display Orders\n"
- + "(4) Display deliveries\n" + "(5) Display Widgets On Hand\n" + "(6) Quit\n");
- Menu choice = Menu.fromId(input.nextInt());
- input.nextLine();
- switch (choice) {
- case NEW_DELIVERY:
- inventory.addDelivery(createNewDelivery());
- 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));
- break;
- case NEW_ORDER:
- inventory.addOrder(createNewOrder());
- 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));
- break;
- case DISPLAY_ORDERS:
- inventory.getOrders().forEach(o -> System.out.println(o));
- inventory.getFulfilledOrders().forEach(f -> System.out.println(f));
- 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));
- break;
- case DISPLAY_DELIVERIES:
- 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));
- break;
- case DISPLAY_WIDGETS_ON_HAND:
- System.out.println("Widgets on hand: " + inventory.getWidgetsOnHand());
- break;
- case QUIT:
- System.exit(0);
- default:
- System.out.println("Invalid menu option, try again");
- break;
- }
- menu();
- }
- }
- /*
- * [Delivery]It has the user to enter numbers
- * [Delivery post-condition] It saves the numbers typed in.
- * It asks price and widgets shipped and allows user to enter numbers.
- */
- public static Delivery createNewDelivery() {
- System.out.print("Enter quantity of widgets shipped: ");
- int quantity = input.nextInt();
- while (quantity <= 0) {
- System.out.println("Negative Number entered, enter positive number: ");
- quantity = input.nextInt();
- }
- System.out.print("Enter unit price: ");
- double unitPrice = input.nextDouble();
- while (unitPrice <= 0.0) {
- System.out.println("Negative Number entered, enter positive number: ");
- unitPrice = input.nextDouble();
- }
- input.nextLine();
- return new Delivery(quantity, unitPrice);
- }
- /*
- * [Order]It has the user to enter numbers
- * [Order post-condition] It saves the numbers typed in.
- * It asks quantity of widgets and allows user to enter numbers.
- */
- public static Order createNewOrder() {
- System.out.print("Enter quantity of widgets to order: ");
- int quantity = input.nextInt();
- while (quantity <= 0) {
- System.out.println("Negative Number entered, enter positive number");
- quantity = input.nextInt();
- }
- input.nextLine();
- return new Order(quantity);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement