Advertisement
Guest User

(Without Indention) Drinks Dealership - Clemente

a guest
Nov 22nd, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 14.70 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Date;
  3. import java.text.*;
  4. public class SoftdrinksDealership
  5. {
  6.  
  7. // Default data of SoftDrinksData
  8. static int[][] SoftDrinksData = {
  9. /*  Stocks      Price */
  10. {20,        30},        // DRINK_SPRITE
  11. {20,        25},        // DRINK_ROYAL
  12. {20,        30},        // DRINK_COKE
  13. {20,        25},        // DRINK_MOUNTAIN
  14. {20,        25},        // DRINK_SARSI
  15. {20,        25},        // DRINK_PEPSI
  16.  
  17. };
  18.  
  19. // Constant of Drinks
  20. final static int
  21. DRINK_NONE      = -1,
  22. DRINK_SPRITE    = 0,
  23. DRINK_ROYAL     = 1,
  24. DRINK_COKE      = 2,
  25. DRINK_MOUNTAIN  = 3,
  26. DRINK_SARSI     = 4,
  27. DRINK_PEPSI     = 5;
  28.  
  29.  
  30. // Constant of Sizes
  31. final static int
  32. SIZE_LARGE      = 1,    // 750 ML
  33. SIZE_MEDIUM     = 2,    // 355 ML
  34. SIZE_AVERAGE    = 3,    // 250 ML
  35. SIZE_SMALL      = 4;    // 240 ML  
  36.  
  37. static int[][] largeSizeDrinks = {
  38. /* Drinks ID        Stocks      Price       */
  39. {DRINK_SPRITE,      20,          350},
  40. {DRINK_ROYAL,       20,          300},
  41. {DRINK_COKE,        20,          200},
  42. {DRINK_MOUNTAIN,    20,          340},
  43. {DRINK_SARSI,       20,          380},
  44. {DRINK_PEPSI,       20,          340}
  45. };
  46.  
  47. static int[][] mediumSizeDrinks = {
  48. /* Drinks ID        Stocks      Price       */
  49. {DRINK_SPRITE,      20,          120},
  50. {DRINK_ROYAL,       20,          130},
  51. {DRINK_NONE,        20,          125},
  52. {DRINK_MOUNTAIN,    20,          100},
  53. {DRINK_NONE,        20,          115},
  54. {DRINK_PEPSI,       20,          126}
  55. };
  56.  
  57. static int[][] averageSizeDrinks = {
  58. /* Drinks ID        Stocks      Price       */
  59. {DRINK_SPRITE,      20,          100},
  60. {DRINK_NONE,        20,          89},
  61. {DRINK_COKE,        20,          95},
  62. {DRINK_MOUNTAIN,    20,          94},
  63. {DRINK_SARSI,       20,          80},
  64. {DRINK_PEPSI,       20,          78}
  65. };
  66.  
  67. static int[][] smallSizeDrinks = {
  68. /* Drinks ID        Stocks      Price       */
  69. {DRINK_SPRITE,      20,          50},
  70. {DRINK_NONE,        20,          51},
  71. {DRINK_NONE,        20,          52},
  72. {DRINK_MOUNTAIN,    20,          40},
  73. {DRINK_SARSI,       20,          45},
  74. {DRINK_PEPSI,       20,          25}
  75. };
  76.  
  77. // Default Sizes of Array
  78. final static int
  79. MAX_CUSTOMER    = 50,
  80. MAX_RECEIPT     = 999,
  81. MAX_DRINKSIZE   = 5;
  82.  
  83. final static String[] MAINMENU = {
  84. "Sell Softdrinks",
  85. "Update Stocks",
  86. "Update Price",
  87. "Delete Stocks",
  88. "Logs of Buyer"
  89. };
  90.  
  91. final static int
  92. MAINMENU_ID             = 0,
  93. SELLSOFDRINKSMENU_ID    = 1,
  94. UPDATESTOCKS_ID         = 2,
  95. UPDATEPRICE_ID          = 3,
  96. DELETESTOCKS_ID         = 4,
  97. LOGSOFBUYER_ID          = 5;
  98.  
  99.  
  100. static String[][] customerData = new String[MAX_CUSTOMER][2]; // 1 = Firstname | 2 = Lastname
  101. static int[][][] customerReceiptData = new int[MAX_RECEIPT][MAX_CUSTOMER][4];
  102. //  0 = Type of Drink | 1 = Drink Size | 2 = Drink Price | 3 =  Drink Case
  103.  
  104. static int
  105. menuStep = MAINMENU_ID,
  106. CUSTOMER_UNIQUE_ID = 0,
  107. RECEIPT_UNIQUE_ID = 0; // DEFAULT
  108.  
  109. static String
  110. customerChoice = "Yes";
  111.  
  112. static Scanner userInput = new Scanner(System.in);
  113.  
  114.  
  115. static String getDrinkName(int id) // METHOD USE TO GET THE DRINK NAME
  116. {
  117. switch(id)
  118. {
  119. case DRINK_NONE:
  120.     return "Not Available";
  121. case DRINK_SPRITE:
  122.     return "SPRITE";
  123. case DRINK_ROYAL:
  124.     return "ROYAL";
  125. case DRINK_COKE:
  126.     return "COKE";
  127. case DRINK_MOUNTAIN:
  128.     return "MOUNTAIN DEW";
  129. case DRINK_SARSI:
  130.     return "SARSI";
  131. case DRINK_PEPSI:
  132.     return "PEPSI";
  133. }
  134. return "";
  135. }
  136.  
  137. static String getDrinkSize(int size) // USE TO GET THE DRINK SIZE NAME
  138. {
  139. switch(size)
  140. {
  141. case SIZE_LARGE:
  142.     return "750 ML";
  143.  
  144. case SIZE_MEDIUM:
  145.     return "355 ML";
  146.  
  147. case SIZE_AVERAGE:
  148.     return "250 ML";
  149. case SIZE_SMALL:
  150.     return "240 ML";
  151. }
  152. return "";
  153. }
  154.  
  155. static int getDrinkPrice(int size, int type)
  156. {
  157. switch(size)
  158. {
  159. case SIZE_LARGE:
  160.     for(int x = 0; x < largeSizeDrinks.length; x ++)
  161.     {
  162.         if(largeSizeDrinks[x][0] != DRINK_NONE && largeSizeDrinks[x][0] == type)
  163.         {
  164.             return largeSizeDrinks[x][2];
  165.         }
  166.     }
  167.  
  168. case SIZE_MEDIUM:
  169.     for(int x = 0; x < mediumSizeDrinks.length; x ++)
  170.     {
  171.         if(mediumSizeDrinks[x][0] != DRINK_NONE && mediumSizeDrinks[x][0] == type)
  172.         {
  173.             return mediumSizeDrinks[x][2];
  174.         }
  175.     }
  176.  
  177. case SIZE_AVERAGE:
  178.     for(int x = 0; x < averageSizeDrinks.length; x ++)
  179.     {
  180.         if(averageSizeDrinks[x][0] != DRINK_NONE && averageSizeDrinks[x][0] == type)
  181.         {
  182.             return averageSizeDrinks[x][2];
  183.         }
  184.     }
  185. case SIZE_SMALL:
  186.     for(int x = 0; x < smallSizeDrinks.length; x ++)
  187.     {
  188.         if(smallSizeDrinks[x][0] != DRINK_NONE && smallSizeDrinks[x][0] == type)
  189.         {
  190.             return smallSizeDrinks[x][2];
  191.         }
  192.     }
  193.  
  194. }
  195. return 0;
  196. }
  197. static void ShowAvailableDrinkSizes(int size)
  198. {
  199. System.out.println("Available Drinks for " + getDrinkSize(size));
  200. System.out.println("ID\tDrinks\tPrice\tAvailable Stocks");
  201. switch(size)
  202. {
  203. case SIZE_LARGE:
  204.     for(int x = 0; x < largeSizeDrinks.length; x ++)
  205.     {
  206.         if(largeSizeDrinks[x][0] != DRINK_NONE)
  207.         {
  208.             System.out.println(x + ".\t" + getDrinkName(largeSizeDrinks[x][0]) + "\t" + largeSizeDrinks[x][2] + "\t" + largeSizeDrinks[x][1]);
  209.         }
  210.         else System.out.println(x +". -\t-\t-");
  211.     }
  212.     break;
  213. case SIZE_MEDIUM:
  214.     for(int x = 0; x < mediumSizeDrinks.length; x ++)
  215.     {
  216.         if(mediumSizeDrinks[x][0] != DRINK_NONE)
  217.         {
  218.             System.out.println(x + ".\t" + getDrinkName(mediumSizeDrinks[x][0]) + "\t" + mediumSizeDrinks[x][2] + "\t" + mediumSizeDrinks[x][1]);
  219.         }
  220.         else System.out.println(x +". -\t-\t-");
  221.     }
  222.  
  223.     break;
  224. case SIZE_AVERAGE:
  225.     for(int x = 0; x < averageSizeDrinks.length; x ++)
  226.     {
  227.         if(averageSizeDrinks[x][0] != DRINK_NONE)
  228.         {
  229.             System.out.println(x + ".\t" + getDrinkName(averageSizeDrinks[x][0]) + "\t" + averageSizeDrinks[x][2] + "\t" + averageSizeDrinks[x][1]);
  230.         }
  231.         else System.out.println(x +". -\t-\t-");
  232.     }
  233.  
  234.     break;
  235. case SIZE_SMALL:
  236.     for(int x = 0; x < smallSizeDrinks.length; x ++)
  237.     {
  238.         if(smallSizeDrinks[x][0] != DRINK_NONE)
  239.         {
  240.             System.out.println(x + ".\t" + getDrinkName(smallSizeDrinks[x][0]) + "\t" + smallSizeDrinks[x][2] + "\t" + smallSizeDrinks[x][1]);
  241.         }
  242.         else System.out.println(x +". -\t-\t-");
  243.     }
  244.  
  245.     break;
  246. }
  247. }
  248.  
  249.  
  250.  
  251. public static void main(String[] args)
  252. {
  253. while(true)
  254. {
  255. int temp = 0;
  256. switch(menuStep)
  257. {
  258.     case MAINMENU_ID:
  259.         System.out.println("BARKI SOFTDRINKS DEALERSHIP");
  260.         System.out.println("MAIN MENU");
  261.         for(int x = 0; x < MAINMENU.length; x++)
  262.         {
  263.             System.out.println("(" + (x + 1) + ") " + MAINMENU[x]);
  264.         }
  265.  
  266.         System.out.print("\nChoose from the menu above: ");
  267.         menuStep = userInput.nextInt();
  268.         break;
  269.     case SELLSOFDRINKSMENU_ID:
  270.         boolean buyAnother = false;
  271.         while(true)
  272.         {
  273.             userInput = new Scanner(System.in); // RESETTING THE VALUE OF USERINPUT
  274.             System.out.print("\nBuy softdrinks? (Yes/No): ");
  275.             customerChoice = userInput.nextLine();
  276.             if(customerChoice.equalsIgnoreCase("Yes") || customerChoice.equalsIgnoreCase("No"))
  277.                 break;
  278.         }
  279.         if(customerChoice.equalsIgnoreCase("No"))
  280.         {
  281.             // We're going to stop the operation and go back to main
  282.             menuStep = MAINMENU_ID; // SET MENUSTEP BACK TO MAIN MENU  
  283.             break;
  284.         }
  285.         String
  286.             _firstName = "",
  287.             _lastName = "";
  288.  
  289.         while(true)
  290.         {  
  291.  
  292.             int
  293.                 _sizeDrinks = SIZE_SMALL, // Default is Small Size
  294.                 _typeDrinks = DRINK_NONE, // -1 value
  295.                 _numberDrinks = 0;        // 0 Case
  296.            
  297.             for(int x = 0; x < MAX_DRINKSIZE; x++)
  298.             {
  299.                 System.out.println("(" + (x + 1) + ") " + ((x != MAX_DRINKSIZE-1) ? (getDrinkSize(x + 1)) : ("Back to Main Menu")));
  300.             }
  301.            
  302.  
  303.  
  304.             System.out.print("\n\nChoose among the sizes of drinks: ");
  305.             _sizeDrinks = userInput.nextInt();
  306.             if(_sizeDrinks == MAX_DRINKSIZE) // BACK TO MAIN MENU
  307.             {
  308.                 // ERASE ALL THE DATA BECAUSE THE CUSTOMER DIDN'T BUY DRINKS
  309.                 //customerReceiptData[RECEIPT_UNIQUE_ID][CUSTOMER_UNIQUE_ID][3] = 0; // SET TO 0
  310.                 //customerData[CUSTOMER_UNIQUE_ID][1] = ""; // LASTNAME
  311.                 //customerData[CUSTOMER_UNIQUE_ID][0] = ""; // FIRSTNAME
  312.                 menuStep = MAINMENU_ID; // SET MENUSTEP BACK TO MAIN MENU  
  313.                 break; // BREAKING THE SWITCH CASE STATEMENT AND GOES BACK IN LOOPING FROM THE START
  314.             }
  315.  
  316.             ShowAvailableDrinkSizes(_sizeDrinks); // Lets show the user the available Drinks for the size
  317.             System.out.print("\n\nChoose a drink you want to purchase: ");
  318.             _typeDrinks = userInput.nextInt();
  319.  
  320.             System.out.print("How many case?: ");
  321.             _numberDrinks = userInput.nextInt();
  322.            
  323.             if(!buyAnother)
  324.             {
  325.                 userInput = new Scanner(System.in); // RESETTING THE VALUE OF USERINPUT
  326.  
  327.                 System.out.print("\n\nEnter Surname: ");
  328.                 _lastName = userInput.nextLine();
  329.                
  330.                
  331.                 System.out.print("Enter First name: ");
  332.                 _firstName = userInput.nextLine();
  333.             }
  334.            
  335.  
  336.             System.out.println(); // BREAKING THE LINE
  337.  
  338.             while(true)
  339.             {
  340.                 userInput = new Scanner(System.in); // RESETTING THE VALUE OF USERINPUT
  341.                 System.out.println("\n1. Show receipt\n2. Back to sell drinks\n3. Back to the menu");
  342.                 System.out.print("Choose what do you want to do next?: ");
  343.                 temp = userInput.nextInt();
  344.                 if(temp > 0 || temp < 4)
  345.                     break; // break the loop if the user choose between 1 , 2 and 3. if not then loop again.
  346.             }
  347.             if(temp == 1)
  348.             {
  349.                
  350.                
  351.                 // Set the customer receipt data
  352.                 customerData[CUSTOMER_UNIQUE_ID][1] = _lastName; // Set the customer Last Name
  353.                 customerData[CUSTOMER_UNIQUE_ID][0] = _firstName; // Set the customer Name
  354.  
  355.                 //  0 = Type of Drink | 1 = Drink Size | 2 = Drink Price | 3 =  Drink Case
  356.                 customerReceiptData[RECEIPT_UNIQUE_ID][CUSTOMER_UNIQUE_ID][3] = _numberDrinks; // DRINK CASE
  357.                 customerReceiptData[RECEIPT_UNIQUE_ID][CUSTOMER_UNIQUE_ID][2] = getDrinkPrice(_sizeDrinks, _typeDrinks); // Drink Price
  358.                 customerReceiptData[RECEIPT_UNIQUE_ID][CUSTOMER_UNIQUE_ID][1] = _sizeDrinks; // Drink Size
  359.                 customerReceiptData[RECEIPT_UNIQUE_ID][CUSTOMER_UNIQUE_ID][0] = _typeDrinks; // Type of Drink
  360.  
  361.                 Date dNow = new Date( );
  362.                     SimpleDateFormat ft = new SimpleDateFormat ("E MM/dd/yyyy \n            'at' hh:mm a");
  363.  
  364.                     System.out.print("\n      ==========RECEIPT==========");
  365.                 System.out.println("\nDate And Time Issued: " + ft.format(dNow));
  366.                 System.out.println("Valid until Tue 12/31/2019");
  367.  
  368.                 System.out.println("\nLists of orders:");
  369.                 System.out.println("Drinks\t\tSize\tPrice\tQuantity");
  370.                 int total = 0;                         
  371.                 for(int x = 0; x < MAX_RECEIPT; x++)
  372.                 {
  373.                     if(customerReceiptData[x][CUSTOMER_UNIQUE_ID][3] > 0)
  374.                     {
  375.                         System.out.println("- " + getDrinkName(customerReceiptData[x][CUSTOMER_UNIQUE_ID][0]) + "\t\t" + getDrinkSize(customerReceiptData[x][CUSTOMER_UNIQUE_ID][1]) + "\t$" + customerReceiptData[x][CUSTOMER_UNIQUE_ID][2] + "\t" + customerReceiptData[x][CUSTOMER_UNIQUE_ID][3]);
  376.                         total += customerReceiptData[x][CUSTOMER_UNIQUE_ID][2] * customerReceiptData[x][CUSTOMER_UNIQUE_ID][3];
  377.                     }
  378.                 }
  379.                 System.out.print("  \n       =========PAY OUT========= ");
  380.                     System.out.println("\nTOTAL: $"+total+"\n\n");
  381.  
  382.  
  383.                 // Increment the unique ID
  384.                 CUSTOMER_UNIQUE_ID++;    // WE NEED TO INCREMENT THIS IS TO AVOID DUPLICATION OF UNIQUE ID JUST LIKE IN DATABASE
  385.                 RECEIPT_UNIQUE_ID++;    // WE NEED TO INCREMENT THIS IS TO AVOID DUPLICATION OF UNIQUE ID JUST LIKE IN DATABASE
  386.  
  387.  
  388.                 // After showing the receipt
  389.                 menuStep = MAINMENU_ID; // SET MENUSTEP BACK TO MAIN MENU
  390.                 break;
  391.             }
  392.             else if(temp == 2) // Just loop back to buy drinks
  393.             {
  394.                 buyAnother = true; // Set this to true if the user want to buy more drinks
  395.  
  396.                 // We're going to set this data just incase the user wanted to buy more drinks
  397.  
  398.                 //  0 = Type of Drink | 1 = Drink Size | 2 = Drink Price | 3 =  Drink Case
  399.                 customerReceiptData[RECEIPT_UNIQUE_ID][CUSTOMER_UNIQUE_ID][3] = _numberDrinks; // DRINK CASE
  400.                 customerReceiptData[RECEIPT_UNIQUE_ID][CUSTOMER_UNIQUE_ID][2] = getDrinkPrice(_sizeDrinks, _typeDrinks); // Drink Price
  401.                 customerReceiptData[RECEIPT_UNIQUE_ID][CUSTOMER_UNIQUE_ID][1] = _sizeDrinks; // Drink Size
  402.                 customerReceiptData[RECEIPT_UNIQUE_ID][CUSTOMER_UNIQUE_ID][0] = _typeDrinks; // Type of Drink
  403.                 // We're just going to increment the Receipt ID to insure no logs of bought by the user being replace infinite.
  404.                 RECEIPT_UNIQUE_ID++;    // WE NEED TO INCREMENT THIS IS TO AVOID DUPLICATION OF UNIQUE ID JUST LIKE IN DATABASE
  405.             }
  406.             else { // Successful bought the Drink
  407.  
  408.  
  409.                 // Set the customer receipt data
  410.                 customerData[CUSTOMER_UNIQUE_ID][1] = _lastName; // Set the customer Last Name
  411.                 customerData[CUSTOMER_UNIQUE_ID][0] = _firstName; // Set the customer Name
  412.  
  413.                 //  0 = Type of Drink | 1 = Drink Size | 2 = Drink Price | 3 =  Drink Case
  414.                 customerReceiptData[RECEIPT_UNIQUE_ID][CUSTOMER_UNIQUE_ID][3] = _numberDrinks; // DRINK CASE
  415.                 customerReceiptData[RECEIPT_UNIQUE_ID][CUSTOMER_UNIQUE_ID][2] = getDrinkPrice(_sizeDrinks, _typeDrinks); // Drink Price
  416.                 customerReceiptData[RECEIPT_UNIQUE_ID][CUSTOMER_UNIQUE_ID][1] = _sizeDrinks; // Drink Size
  417.                 customerReceiptData[RECEIPT_UNIQUE_ID][CUSTOMER_UNIQUE_ID][0] = _typeDrinks; // Type of Drink
  418.  
  419.                 // Increment the unique ID
  420.                 CUSTOMER_UNIQUE_ID++;    // WE NEED TO INCREMENT THIS IS TO AVOID DUPLICATION OF UNIQUE ID JUST LIKE IN DATABASE
  421.                 RECEIPT_UNIQUE_ID++;    // WE NEED TO INCREMENT THIS IS TO AVOID DUPLICATION OF UNIQUE ID JUST LIKE IN DATABASE
  422.                 menuStep = MAINMENU_ID; // SET MENUSTEP BACK TO MAIN MENU  
  423.                 break;
  424.             }
  425.         }
  426.         break;
  427.     case UPDATESTOCKS_ID:
  428.  
  429.         System.out.println("UPDATE STOCKS");
  430.         System.out.println("ID\tNAME\t\tSTOCK");
  431.         for(int x = 0; x < SoftDrinksData.length; x++) // SoftDrinksData.length = get the number of row of SoftDrinksData
  432.         {
  433.             System.out.println((x + 1) + "\t" + getDrinkName(x) + "\t\t" +  SoftDrinksData[x][0] + " left");
  434.             if(x == SoftDrinksData.length -1 ) System.out.println((SoftDrinksData.length + 1) + "\t" + "to Go back to Main Menu");
  435.         }
  436.         System.out.print("~Select Variant you want to update: ");
  437.         temp = userInput.nextInt();
  438.         menuStep = MAINMENU_ID; // SET MENUSTEP BACK TO MAIN MENU AFTER THE STOCK UPDATES
  439.         break;
  440.     case UPDATEPRICE_ID:
  441.  
  442.         break;
  443.     case DELETESTOCKS_ID:
  444.  
  445.         break;
  446.     case LOGSOFBUYER_ID:
  447.         while(true)
  448.         {
  449.             System.out.println("\nLOGS OF BUYERS\n");
  450.             for(int x = 0; x < MAX_CUSTOMER; x++)
  451.             {
  452.                 if(customerData[x][1] != null)
  453.                 {
  454.                     System.out.println("Customer Details: " + (x + 1) + ". " + customerData[x][1] + ", " + customerData[x][0]);
  455.                     System.out.println("Drinks\t\tSize\tPrice\tQuantity");
  456.                     int total = 0;                         
  457.                     for(int y = 0; y < MAX_RECEIPT; y++)
  458.                     {
  459.                         if(customerReceiptData[y][x][3] > 0)
  460.                         {
  461.                             System.out.println("- " + getDrinkName(customerReceiptData[y][x][0]) + "\t\t" + getDrinkSize(customerReceiptData[y][x][1]) + "\t$" + customerReceiptData[y][x][2] + "\t" + customerReceiptData[y][x][3]);
  462.                             total += customerReceiptData[y][x][2] * customerReceiptData[y][x][3];
  463.                         }
  464.                     }
  465.                     System.out.println("\nTOTAL: $"+total);
  466.                     System.out.println("===================================================");
  467.                     System.out.println();
  468.                 }
  469.             }
  470.             userInput = new Scanner(System.in);
  471.             System.out.print("\n Back to Main Menu? (Yes/No): ");
  472.             customerChoice = userInput.nextLine();
  473.             if(customerChoice.equalsIgnoreCase("Yes")) 
  474.                 break;
  475.             menuStep = MAINMENU_ID; // SET MENUSTEP BACK TO MAIN MENU AFTER THE CHECKING THE LOGS
  476.            
  477.         }
  478.         break;
  479. }
  480. }
  481. }
  482. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement