HarrJ

Day 28 out

Jul 21st, 2024 (edited)
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.61 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Day28A {
  4.     public static void main(String[] args) {
  5.         Day28Methods callMethods = new Day28Methods();
  6.         Scanner sc = new Scanner(System.in);
  7.         String userChoice;
  8.         String name;
  9.         String category;
  10.         double price;
  11.         int qty;
  12.        
  13.         System.out.println("Choose an option: ");
  14.         System.out.println("1 - Add new row");
  15.         System.out.println("2 - Show all row");
  16.         System.out.print(">> ");
  17.         userChoice = sc.nextLine();
  18.        
  19.         switch (userChoice) {
  20.             case "1":
  21.                 System.out.println("Enter value for new row:");
  22.                 try {
  23.                     System.out.print("Product name: ");
  24.                     name = sc.nextLine();
  25.                     System.out.print("Category: ");
  26.                     category = sc.nextLine();
  27.                     System.out.print("Price: ");
  28.                     price = sc.nextDouble();
  29.                     sc.nextLine();
  30.                     System.out.print("Quantity: ");
  31.                     qty = sc.nextInt();
  32.                    
  33.                     String result = callMethods.addNewRow(name, category, price, qty);
  34.                     System.out.println(">>> " + result + " <<<");
  35.                 } catch (Exception e) {
  36.                     System.out.println("error(sc): " + e.toString());
  37.                 }
  38.                 break;
  39.             case "2":
  40.                 callMethods.getAllRows();
  41.                 break;
  42.             default:
  43.                 System.out.println("option is invalid");
  44.         }
  45.     }
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment