Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.Date;
- import java.text.*;
- public class SoftdrinksDealership
- {
- // Default data of SoftDrinksData
- static int[][] SoftDrinksData = {
- /* Stocks Price */
- {20, 30}, // DRINK_SPRITE
- {20, 25}, // DRINK_ROYAL
- {20, 30}, // DRINK_COKE
- {20, 25}, // DRINK_MOUNTAIN
- {20, 25}, // DRINK_SARSI
- {20, 25}, // DRINK_PEPSI
- };
- // Constant of Drinks
- final static int
- DRINK_NONE = -1,
- DRINK_SPRITE = 0,
- DRINK_ROYAL = 1,
- DRINK_COKE = 2,
- DRINK_MOUNTAIN = 3,
- DRINK_SARSI = 4,
- DRINK_PEPSI = 5;
- // Constant of Sizes
- final static int
- SIZE_LARGE = 1, // 750 ML
- SIZE_MEDIUM = 2, // 355 ML
- SIZE_AVERAGE = 3, // 250 ML
- SIZE_SMALL = 4; // 240 ML
- static int[][] largeSizeDrinks = {
- /* Drinks ID Stocks Price */
- {DRINK_SPRITE, 20, 350},
- {DRINK_ROYAL, 20, 300},
- {DRINK_COKE, 20, 200},
- {DRINK_MOUNTAIN, 20, 340},
- {DRINK_SARSI, 20, 380},
- {DRINK_PEPSI, 20, 340}
- };
- static int[][] mediumSizeDrinks = {
- /* Drinks ID Stocks Price */
- {DRINK_SPRITE, 20, 120},
- {DRINK_ROYAL, 20, 130},
- {DRINK_NONE, 20, 125},
- {DRINK_MOUNTAIN, 20, 100},
- {DRINK_NONE, 20, 115},
- {DRINK_PEPSI, 20, 126}
- };
- static int[][] averageSizeDrinks = {
- /* Drinks ID Stocks Price */
- {DRINK_SPRITE, 20, 100},
- {DRINK_NONE, 20, 89},
- {DRINK_COKE, 20, 95},
- {DRINK_MOUNTAIN, 20, 94},
- {DRINK_SARSI, 20, 80},
- {DRINK_PEPSI, 20, 78}
- };
- static int[][] smallSizeDrinks = {
- /* Drinks ID Stocks Price */
- {DRINK_SPRITE, 20, 50},
- {DRINK_NONE, 20, 51},
- {DRINK_NONE, 20, 52},
- {DRINK_MOUNTAIN, 20, 40},
- {DRINK_SARSI, 20, 45},
- {DRINK_PEPSI, 20, 25}
- };
- // Default Sizes of Array
- final static int
- MAX_CUSTOMER = 50,
- MAX_RECEIPT = 999,
- MAX_DRINKSIZE = 5;
- final static String[] MAINMENU = {
- "Sell Softdrinks",
- "Update Stocks",
- "Update Price",
- "Delete Stocks",
- "Logs of Buyer"
- };
- final static int
- MAINMENU_ID = 0,
- SELLSOFDRINKSMENU_ID = 1,
- UPDATESTOCKS_ID = 2,
- UPDATEPRICE_ID = 3,
- DELETESTOCKS_ID = 4,
- LOGSOFBUYER_ID = 5;
- static String[][] customerData = new String[MAX_CUSTOMER][2]; // 1 = Firstname | 2 = Lastname
- static int[][][] customerReceiptData = new int[MAX_RECEIPT][MAX_CUSTOMER][4];
- // 0 = Type of Drink | 1 = Drink Size | 2 = Drink Price | 3 = Drink Case
- static int
- menuStep = MAINMENU_ID,
- CUSTOMER_UNIQUE_ID = 0,
- RECEIPT_UNIQUE_ID = 0; // DEFAULT
- static String
- customerChoice = "Yes";
- static Scanner userInput = new Scanner(System.in);
- static String getDrinkName(int id) // METHOD USE TO GET THE DRINK NAME
- {
- switch(id)
- {
- case DRINK_NONE:
- return "Not Available";
- case DRINK_SPRITE:
- return "SPRITE";
- case DRINK_ROYAL:
- return "ROYAL";
- case DRINK_COKE:
- return "COKE";
- case DRINK_MOUNTAIN:
- return "MOUNTAIN DEW";
- case DRINK_SARSI:
- return "SARSI";
- case DRINK_PEPSI:
- return "PEPSI";
- }
- return "";
- }
- static String getDrinkSize(int size) // USE TO GET THE DRINK SIZE NAME
- {
- switch(size)
- {
- case SIZE_LARGE:
- return "750 ML";
- case SIZE_MEDIUM:
- return "355 ML";
- case SIZE_AVERAGE:
- return "250 ML";
- case SIZE_SMALL:
- return "240 ML";
- }
- return "";
- }
- static int getDrinkPrice(int size, int type)
- {
- switch(size)
- {
- case SIZE_LARGE:
- for(int x = 0; x < largeSizeDrinks.length; x ++)
- {
- if(largeSizeDrinks[x][0] != DRINK_NONE && largeSizeDrinks[x][0] == type)
- {
- return largeSizeDrinks[x][2];
- }
- }
- case SIZE_MEDIUM:
- for(int x = 0; x < mediumSizeDrinks.length; x ++)
- {
- if(mediumSizeDrinks[x][0] != DRINK_NONE && mediumSizeDrinks[x][0] == type)
- {
- return mediumSizeDrinks[x][2];
- }
- }
- case SIZE_AVERAGE:
- for(int x = 0; x < averageSizeDrinks.length; x ++)
- {
- if(averageSizeDrinks[x][0] != DRINK_NONE && averageSizeDrinks[x][0] == type)
- {
- return averageSizeDrinks[x][2];
- }
- }
- case SIZE_SMALL:
- for(int x = 0; x < smallSizeDrinks.length; x ++)
- {
- if(smallSizeDrinks[x][0] != DRINK_NONE && smallSizeDrinks[x][0] == type)
- {
- return smallSizeDrinks[x][2];
- }
- }
- }
- return 0;
- }
- static void ShowAvailableDrinkSizes(int size)
- {
- System.out.println("Available Drinks for " + getDrinkSize(size));
- System.out.println("ID\tDrinks\tPrice\tAvailable Stocks");
- switch(size)
- {
- case SIZE_LARGE:
- for(int x = 0; x < largeSizeDrinks.length; x ++)
- {
- if(largeSizeDrinks[x][0] != DRINK_NONE)
- {
- System.out.println(x + ".\t" + getDrinkName(largeSizeDrinks[x][0]) + "\t" + largeSizeDrinks[x][2] + "\t" + largeSizeDrinks[x][1]);
- }
- else System.out.println(x +". -\t-\t-");
- }
- break;
- case SIZE_MEDIUM:
- for(int x = 0; x < mediumSizeDrinks.length; x ++)
- {
- if(mediumSizeDrinks[x][0] != DRINK_NONE)
- {
- System.out.println(x + ".\t" + getDrinkName(mediumSizeDrinks[x][0]) + "\t" + mediumSizeDrinks[x][2] + "\t" + mediumSizeDrinks[x][1]);
- }
- else System.out.println(x +". -\t-\t-");
- }
- break;
- case SIZE_AVERAGE:
- for(int x = 0; x < averageSizeDrinks.length; x ++)
- {
- if(averageSizeDrinks[x][0] != DRINK_NONE)
- {
- System.out.println(x + ".\t" + getDrinkName(averageSizeDrinks[x][0]) + "\t" + averageSizeDrinks[x][2] + "\t" + averageSizeDrinks[x][1]);
- }
- else System.out.println(x +". -\t-\t-");
- }
- break;
- case SIZE_SMALL:
- for(int x = 0; x < smallSizeDrinks.length; x ++)
- {
- if(smallSizeDrinks[x][0] != DRINK_NONE)
- {
- System.out.println(x + ".\t" + getDrinkName(smallSizeDrinks[x][0]) + "\t" + smallSizeDrinks[x][2] + "\t" + smallSizeDrinks[x][1]);
- }
- else System.out.println(x +". -\t-\t-");
- }
- break;
- }
- }
- public static void main(String[] args)
- {
- while(true)
- {
- int temp = 0;
- switch(menuStep)
- {
- case MAINMENU_ID:
- System.out.println("BARKI SOFTDRINKS DEALERSHIP");
- System.out.println("MAIN MENU");
- for(int x = 0; x < MAINMENU.length; x++)
- {
- System.out.println("(" + (x + 1) + ") " + MAINMENU[x]);
- }
- System.out.print("\nChoose from the menu above: ");
- menuStep = userInput.nextInt();
- break;
- case SELLSOFDRINKSMENU_ID:
- boolean buyAnother = false;
- while(true)
- {
- userInput = new Scanner(System.in); // RESETTING THE VALUE OF USERINPUT
- System.out.print("\nBuy softdrinks? (Yes/No): ");
- customerChoice = userInput.nextLine();
- if(customerChoice.equalsIgnoreCase("Yes") || customerChoice.equalsIgnoreCase("No"))
- break;
- }
- if(customerChoice.equalsIgnoreCase("No"))
- {
- // We're going to stop the operation and go back to main
- menuStep = MAINMENU_ID; // SET MENUSTEP BACK TO MAIN MENU
- break;
- }
- String
- _firstName = "",
- _lastName = "";
- while(true)
- {
- int
- _sizeDrinks = SIZE_SMALL, // Default is Small Size
- _typeDrinks = DRINK_NONE, // -1 value
- _numberDrinks = 0; // 0 Case
- for(int x = 0; x < MAX_DRINKSIZE; x++)
- {
- System.out.println("(" + (x + 1) + ") " + ((x != MAX_DRINKSIZE-1) ? (getDrinkSize(x + 1)) : ("Back to Main Menu")));
- }
- System.out.print("\n\nChoose among the sizes of drinks: ");
- _sizeDrinks = userInput.nextInt();
- if(_sizeDrinks == MAX_DRINKSIZE) // BACK TO MAIN MENU
- {
- // ERASE ALL THE DATA BECAUSE THE CUSTOMER DIDN'T BUY DRINKS
- //customerReceiptData[RECEIPT_UNIQUE_ID][CUSTOMER_UNIQUE_ID][3] = 0; // SET TO 0
- //customerData[CUSTOMER_UNIQUE_ID][1] = ""; // LASTNAME
- //customerData[CUSTOMER_UNIQUE_ID][0] = ""; // FIRSTNAME
- menuStep = MAINMENU_ID; // SET MENUSTEP BACK TO MAIN MENU
- break; // BREAKING THE SWITCH CASE STATEMENT AND GOES BACK IN LOOPING FROM THE START
- }
- ShowAvailableDrinkSizes(_sizeDrinks); // Lets show the user the available Drinks for the size
- System.out.print("\n\nChoose a drink you want to purchase: ");
- _typeDrinks = userInput.nextInt();
- System.out.print("How many case?: ");
- _numberDrinks = userInput.nextInt();
- if(!buyAnother)
- {
- userInput = new Scanner(System.in); // RESETTING THE VALUE OF USERINPUT
- System.out.print("\n\nEnter Surname: ");
- _lastName = userInput.nextLine();
- System.out.print("Enter First name: ");
- _firstName = userInput.nextLine();
- }
- System.out.println(); // BREAKING THE LINE
- while(true)
- {
- userInput = new Scanner(System.in); // RESETTING THE VALUE OF USERINPUT
- System.out.println("\n1. Show receipt\n2. Back to sell drinks\n3. Back to the menu");
- System.out.print("Choose what do you want to do next?: ");
- temp = userInput.nextInt();
- if(temp > 0 || temp < 4)
- break; // break the loop if the user choose between 1 , 2 and 3. if not then loop again.
- }
- if(temp == 1)
- {
- // Set the customer receipt data
- customerData[CUSTOMER_UNIQUE_ID][1] = _lastName; // Set the customer Last Name
- customerData[CUSTOMER_UNIQUE_ID][0] = _firstName; // Set the customer Name
- // 0 = Type of Drink | 1 = Drink Size | 2 = Drink Price | 3 = Drink Case
- customerReceiptData[RECEIPT_UNIQUE_ID][CUSTOMER_UNIQUE_ID][3] = _numberDrinks; // DRINK CASE
- customerReceiptData[RECEIPT_UNIQUE_ID][CUSTOMER_UNIQUE_ID][2] = getDrinkPrice(_sizeDrinks, _typeDrinks); // Drink Price
- customerReceiptData[RECEIPT_UNIQUE_ID][CUSTOMER_UNIQUE_ID][1] = _sizeDrinks; // Drink Size
- customerReceiptData[RECEIPT_UNIQUE_ID][CUSTOMER_UNIQUE_ID][0] = _typeDrinks; // Type of Drink
- Date dNow = new Date( );
- SimpleDateFormat ft = new SimpleDateFormat ("E MM/dd/yyyy \n 'at' hh:mm a");
- System.out.print("\n ==========RECEIPT==========");
- System.out.println("\nDate And Time Issued: " + ft.format(dNow));
- System.out.println("Valid until Tue 12/31/2019");
- System.out.println("\nLists of orders:");
- System.out.println("Drinks\t\tSize\tPrice\tQuantity");
- int total = 0;
- for(int x = 0; x < MAX_RECEIPT; x++)
- {
- if(customerReceiptData[x][CUSTOMER_UNIQUE_ID][3] > 0)
- {
- 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]);
- total += customerReceiptData[x][CUSTOMER_UNIQUE_ID][2] * customerReceiptData[x][CUSTOMER_UNIQUE_ID][3];
- }
- }
- System.out.print(" \n =========PAY OUT========= ");
- System.out.println("\nTOTAL: $"+total+"\n\n");
- // Increment the unique ID
- CUSTOMER_UNIQUE_ID++; // WE NEED TO INCREMENT THIS IS TO AVOID DUPLICATION OF UNIQUE ID JUST LIKE IN DATABASE
- RECEIPT_UNIQUE_ID++; // WE NEED TO INCREMENT THIS IS TO AVOID DUPLICATION OF UNIQUE ID JUST LIKE IN DATABASE
- // After showing the receipt
- menuStep = MAINMENU_ID; // SET MENUSTEP BACK TO MAIN MENU
- break;
- }
- else if(temp == 2) // Just loop back to buy drinks
- {
- buyAnother = true; // Set this to true if the user want to buy more drinks
- // We're going to set this data just incase the user wanted to buy more drinks
- // 0 = Type of Drink | 1 = Drink Size | 2 = Drink Price | 3 = Drink Case
- customerReceiptData[RECEIPT_UNIQUE_ID][CUSTOMER_UNIQUE_ID][3] = _numberDrinks; // DRINK CASE
- customerReceiptData[RECEIPT_UNIQUE_ID][CUSTOMER_UNIQUE_ID][2] = getDrinkPrice(_sizeDrinks, _typeDrinks); // Drink Price
- customerReceiptData[RECEIPT_UNIQUE_ID][CUSTOMER_UNIQUE_ID][1] = _sizeDrinks; // Drink Size
- customerReceiptData[RECEIPT_UNIQUE_ID][CUSTOMER_UNIQUE_ID][0] = _typeDrinks; // Type of Drink
- // We're just going to increment the Receipt ID to insure no logs of bought by the user being replace infinite.
- RECEIPT_UNIQUE_ID++; // WE NEED TO INCREMENT THIS IS TO AVOID DUPLICATION OF UNIQUE ID JUST LIKE IN DATABASE
- }
- else { // Successful bought the Drink
- // Set the customer receipt data
- customerData[CUSTOMER_UNIQUE_ID][1] = _lastName; // Set the customer Last Name
- customerData[CUSTOMER_UNIQUE_ID][0] = _firstName; // Set the customer Name
- // 0 = Type of Drink | 1 = Drink Size | 2 = Drink Price | 3 = Drink Case
- customerReceiptData[RECEIPT_UNIQUE_ID][CUSTOMER_UNIQUE_ID][3] = _numberDrinks; // DRINK CASE
- customerReceiptData[RECEIPT_UNIQUE_ID][CUSTOMER_UNIQUE_ID][2] = getDrinkPrice(_sizeDrinks, _typeDrinks); // Drink Price
- customerReceiptData[RECEIPT_UNIQUE_ID][CUSTOMER_UNIQUE_ID][1] = _sizeDrinks; // Drink Size
- customerReceiptData[RECEIPT_UNIQUE_ID][CUSTOMER_UNIQUE_ID][0] = _typeDrinks; // Type of Drink
- // Increment the unique ID
- CUSTOMER_UNIQUE_ID++; // WE NEED TO INCREMENT THIS IS TO AVOID DUPLICATION OF UNIQUE ID JUST LIKE IN DATABASE
- RECEIPT_UNIQUE_ID++; // WE NEED TO INCREMENT THIS IS TO AVOID DUPLICATION OF UNIQUE ID JUST LIKE IN DATABASE
- menuStep = MAINMENU_ID; // SET MENUSTEP BACK TO MAIN MENU
- break;
- }
- }
- break;
- case UPDATESTOCKS_ID:
- System.out.println("UPDATE STOCKS");
- System.out.println("ID\tNAME\t\tSTOCK");
- for(int x = 0; x < SoftDrinksData.length; x++) // SoftDrinksData.length = get the number of row of SoftDrinksData
- {
- System.out.println((x + 1) + "\t" + getDrinkName(x) + "\t\t" + SoftDrinksData[x][0] + " left");
- if(x == SoftDrinksData.length -1 ) System.out.println((SoftDrinksData.length + 1) + "\t" + "to Go back to Main Menu");
- }
- System.out.print("~Select Variant you want to update: ");
- temp = userInput.nextInt();
- menuStep = MAINMENU_ID; // SET MENUSTEP BACK TO MAIN MENU AFTER THE STOCK UPDATES
- break;
- case UPDATEPRICE_ID:
- break;
- case DELETESTOCKS_ID:
- break;
- case LOGSOFBUYER_ID:
- while(true)
- {
- System.out.println("\nLOGS OF BUYERS\n");
- for(int x = 0; x < MAX_CUSTOMER; x++)
- {
- if(customerData[x][1] != null)
- {
- System.out.println("Customer Details: " + (x + 1) + ". " + customerData[x][1] + ", " + customerData[x][0]);
- System.out.println("Drinks\t\tSize\tPrice\tQuantity");
- int total = 0;
- for(int y = 0; y < MAX_RECEIPT; y++)
- {
- if(customerReceiptData[y][x][3] > 0)
- {
- 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]);
- total += customerReceiptData[y][x][2] * customerReceiptData[y][x][3];
- }
- }
- System.out.println("\nTOTAL: $"+total);
- System.out.println("===================================================");
- System.out.println();
- }
- }
- userInput = new Scanner(System.in);
- System.out.print("\n Back to Main Menu? (Yes/No): ");
- customerChoice = userInput.nextLine();
- if(customerChoice.equalsIgnoreCase("Yes"))
- break;
- menuStep = MAINMENU_ID; // SET MENUSTEP BACK TO MAIN MENU AFTER THE CHECKING THE LOGS
- }
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement