Advertisement
Guest User

ZomerPOS - Final

a guest
Nov 11th, 2019
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 11.69 KB | None | 0 0
  1. /**
  2.         Name:  Zomer L. Gregorio
  3.         Course & Section:  BSIT 112
  4.         Subject:  Computer Programming 1
  5.         Teacher:  Jerome Austria
  6. **/
  7.  
  8. import java.text.SimpleDateFormat;
  9. import java.util.*;
  10.  
  11. public class ZomerPOS {
  12.     //Date, receipt#, & scanner
  13.     final static Date currentTime = new Date();
  14.     final static SimpleDateFormat sdf = new SimpleDateFormat("EEE, MMM d, yyyy");
  15.     final static SimpleDateFormat receipt = new SimpleDateFormat("yyyyMMddHHmmss");
  16.     static Scanner write = new Scanner(System.in);
  17.     //Product lists, prices, default quantities, etc.
  18.     static int numOfProduct = 35;
  19.     final static String[] productList = {"Chicken Adobo", "Chicken Inasal", "Chicken Curry",
  20.                                          "Chicken Teriyaki", "Fried Chicken", "Pork Adobo",
  21.                                          "Pork Sisig", "Lechon Kawali", "Lechon Paksiw",
  22.                                          "Sinigang", "Beef Caldereta", "Beef Steak",
  23.                                          "Beef Kare-Kare", "Beef Mechado", "Bulalo",
  24.                                          "Cassava Cake",  "Buko Pandan Salad", "Fruit Salad",
  25.                                          "Ginataang Bilo-Bilo",  "Macaroni Salad", "Pichi-Pichi",
  26.                                          "Ube Halaya", "Ice Cream", "Leche Flan", "Halo-Halo",
  27.                                          "Coke", "Sprite", "Royal", "Orange Juice", "Mango Juice",
  28.                                          "Lemon Ice Tea", "Fruit Safari", "Calamansi Slushie",
  29.                                          "Pink Lemonade", "Mint Jito"};
  30.     final static double[] productPrice = {130, 130, 135, 125, 125, 130, 120, 125, 130, 120,
  31.                                           130, 135, 135, 130, 120, 40, 50, 50, 30, 50,
  32.                                           40, 40, 40, 60, 40, 15, 15, 15, 20, 20,
  33.                                           20, 90, 80, 110, 120};
  34.     static int[] productQty = new int[35];                        
  35.     static double taxPercent = 0.05d, amountDue, cash, change, taxAmount, totalAmount;
  36.     static String customerName;
  37.     static int inputRepeat; //Input for repeating the program  
  38.     static int longest = 0, numOfSpaces; //longest character in productList
  39.     private static Scanner scanName = new Scanner(System.in);
  40.    
  41.     public static void main(String[] args) {
  42.         do {
  43.             menu();
  44.             getOrder();
  45.             reviewOrders();
  46.             payment();
  47.             repeatProcess();
  48.         } while (inputRepeat == 1);
  49.     }
  50.    
  51.     public static void menu() {
  52.         //Get length of longest character in productList for display alignment
  53.         for (int i = 0; i < numOfProduct; i++)
  54.             if (longest < productList[i].length())
  55.                  longest = productList[i].length();
  56.         // Display menu
  57.         System.out.print("----------------------------------------------------------");
  58.         System.out.print("\n\t\t\tZOMER'S UNLIRICE RESTAURANT \t\t");
  59.         System.out.print("\n\t       Welcome! Please choose your order.\t");
  60.         System.out.print("\n----------------------------------------------------------");
  61.         System.out.print("\n CODE\t\tPRODUCT\t\t\tPRICE");
  62.         System.out.print("\n\t\t\t\t");
  63.         //Meal
  64.         System.out.print("\n----------------------------------------------------------");
  65.         System.out.print("\n\t\t\t| MEALS |");
  66.         System.out.print("\n----------------------------------------------------------");
  67.         for (int i = 0; i < 9; i++) { //productList [0-8]
  68.             System.out.printf("\n [0%d]\t\t%s", i+1, productList[i]);
  69.             numOfSpaces = longest - productList[i].length() +2;
  70.                 for (int j = 0; j < numOfSpaces; j++)
  71.                     System.out.print(" ");
  72.             System.out.printf("\tPHP %.2f", productPrice[i]);
  73.         }
  74.         for (int i = 9; i < 15; i++) { //productList [9-14]
  75.             System.out.printf("\n [%d]\t\t%s", i+1, productList[i]);
  76.             numOfSpaces = longest - productList[i].length() +2;
  77.                 for (int j = 0; j < numOfSpaces; j++)
  78.                     System.out.print(" ");
  79.             System.out.printf("\tPHP %.2f", productPrice[i]);
  80.         }
  81.         //Desserts
  82.         System.out.print("\n----------------------------------------------------------");
  83.         System.out.print("\n\t\t\t| DESSERTS |");
  84.         System.out.print("\n----------------------------------------------------------");
  85.         for (int i = 15; i < 25; i++) { //productList [15-24]
  86.             System.out.printf("\n [%d]\t\t%s", i+1, productList[i]);
  87.             numOfSpaces = longest - productList[i].length() +2;
  88.                 for (int j = 0; j < numOfSpaces; j++)
  89.                     System.out.print(" ");
  90.             System.out.printf("\tPHP %.2f", productPrice[i]);
  91.         }
  92.         //Drinks
  93.         System.out.print("\n----------------------------------------------------------");
  94.         System.out.print("\n\t\t\t| DRINKS |");
  95.         System.out.print("\n----------------------------------------------------------");
  96.         for (int i = 25; i < 35; i++) { //productList [25-34]
  97.             System.out.printf("\n [%d]\t\t%s", i+1, productList[i]);
  98.             numOfSpaces = longest - productList[i].length() +2;
  99.                 for (int j = 0; j < numOfSpaces; j++)
  100.                     System.out.print(" ");
  101.             System.out.printf("\tPHP %.2f", productPrice[i]); // END
  102.         }
  103.         System.out.print("\n----------------------------------------------------------");
  104.         System.out.print("\nEnter product code & quantity to place the order.");
  105.         System.out.print("\nEnter negative number to quantity to delete the product(s) you ordered.");
  106.         System.out.print("\nEnter 0[zero] to product code if you wish to review or finish your order(s).\n");
  107.     } //End of menu() method
  108.    
  109.     public static void getOrder() {
  110.         int code, qty;     
  111.         while (true) {
  112.             System.out.print("\nEnter Product Code: ");            
  113.             if (!write.hasNextInt()){ //Input Mismatch Exception Handler
  114.                 System.out.print("Invalid product code. Please try again.");
  115.                 write.next(); //discard
  116.                 continue;
  117.             }
  118.             code = write.nextInt();
  119.             if (code > 0 && code < 16) {
  120.                 System.out.print("Meal: " + productList[code-1] + "\n");
  121.             }
  122.             else if (code > 15 && code < 26) {
  123.                 System.out.print("Dessert: " + productList[code-1] + "\n");
  124.             }
  125.             else if (code > 25 && code < 36) {
  126.                 System.out.print("Drink: " + productList[code-1] + "\n");
  127.             }          
  128.             //Execute loop if user enters below 0 or above product code    
  129.             else if (code < 0 ||  code > numOfProduct) {
  130.                 System.out.print("Invalid product code. Please try again.");
  131.                 continue;
  132.             }
  133.              else if (code == 0)
  134.              break;
  135.         while (true) {
  136.             System.out.print("Enter Product Quantity: ");              
  137.             if (!write.hasNextInt()) { //Input Mismatch Exception Handler
  138.                 System.out.print("Invalid input. Please try again.\n");
  139.                 write.next(); //discard
  140.                 continue;
  141.             }
  142.             qty = write.nextInt();
  143.             if (qty > 0) {
  144.                 productQty[code-1] += qty;
  145.             }
  146.             else if  (qty == 0) {
  147.                 System.out.print("Cancelled.\n");
  148.             }
  149.             //Deleted ordered products
  150.             else if (qty < 0 && productQty[code-1] >= Math.abs(qty)) {
  151.                 productQty[code-1] -= Math.abs(qty);
  152.                 System.out.print(productList[code-1] + ": " + Math.abs(qty) + " quantity deleted.\n");
  153.             }
  154.             else if (qty < 0 && productQty[code-1] < Math.abs(qty)) {
  155.                 System.out.print("Not enough quantites to be deleted. ");
  156.                 System.out.print("Please try again.\n");
  157.                 continue;
  158.             }
  159.             break;
  160.             }
  161.         }
  162.     } //End of getOrder() method
  163.    
  164.     public static void reviewOrders() {
  165.         while (true) {
  166.             // Display & review ordered products & total amount to be paid
  167.             System.out.print("\nReview Order(s): ");                                           
  168.             for (int i = 0; i < numOfProduct; i++) {
  169.                 if (productQty[i] > 0) {
  170.                     System.out.printf("\nCode %d\t%s", i+1, productList[i]);
  171.                     numOfSpaces = longest - productList[i].length()+3;
  172.                         for (int j = 0; j < numOfSpaces; j++)
  173.                             System.out.print(" ");
  174.                     System.out.printf("Qty: %d\t Subtotal: PHP %.2f", productQty[i], productPrice[i] * productQty[i]);
  175.                 }
  176.             }
  177.             for (int i = 0; i < numOfProduct; i++) {
  178.                 amountDue += productPrice[i] * productQty[i]; //Computation of amountDue
  179.             }      
  180.             taxAmount = amountDue * taxPercent;
  181.             totalAmount = amountDue + taxAmount; //Total amount to be paid
  182.             System.out.printf("\n\nAmount Due: \t\tPHP %.2f", amountDue);
  183.             System.out.print("\n5% Tax Charge: ");
  184.             System.out.printf("\t\tPHP %.2f", taxAmount);
  185.             System.out.printf("\nTotal Amount: \t\tPHP %.2f", totalAmount);
  186.             System.out.print("\n-----------------------------------------------------------");
  187.             System.out.print("\nDo you want to finish your order?\nEnter 1 for Yes or 0 for No: ");    
  188.             while (true) { 
  189.                 if (!write.hasNextInt()) { //Input Mismatch Exception Handler
  190.                     System.out.print("Please enter 1 or 0 only: ");
  191.                     write.next(); //discard
  192.                     continue;
  193.                 }
  194.                 int orderAns = write.nextInt();
  195.                 if (orderAns == 1) {
  196.                     return;
  197.                 }
  198.                 else if (orderAns == 0) {
  199.                     getOrder();
  200.                 }
  201.                 else {
  202.                     System.out.print("Please enter 1 or 0 only: ");
  203.                     continue;
  204.                 }
  205.             break;
  206.             }  
  207.         }
  208.     } //End of reviewOrders() method
  209.    
  210.     public static void payment() {
  211.         // Getting customer name & cash
  212.         System.out.print("\n\nPayment");
  213.         System.out.print("\nPlease enter your name: ");
  214.         customerName = scanName.nextLine();        
  215.         while (true) {                 
  216.             System.out.print("Enter Cash: PHP ");              
  217.             if (!write.hasNextDouble()){ //Input Mismatch Exception Handler
  218.                 System.out.print("Please enter a valid amount.\n");
  219.                 write.next(); //discard
  220.                 continue;
  221.             }
  222.             cash = write.nextDouble();
  223.             if (cash >= totalAmount) {
  224.                 change = cash - totalAmount;           
  225.                 //Print  receipt
  226.                 System.out.print("\n\n\n***********************************************************");
  227.                 System.out.print("\n\t\t\t\tZomer's Unlirice Restaurant");
  228.                 System.out.print("\n\t\t\t\t Alabang, Muntinlupa City");
  229.                 System.out.print("\n***********************************************************");
  230.                 System.out.print("\nReceipt #: " + receipt.format(currentTime));
  231.                 System.out.print("\nDate: " + sdf.format(currentTime));
  232.                 System.out.print("\nCustomer Name: " + customerName);
  233.                 System.out.print("\n***********************************************************");
  234.                 System.out.print("\nORDER: \n\tProduct\t\t\t\tQuantity\t\tSubtotal");
  235.                 for (int i = 0; i < numOfProduct; i++) {
  236.                     if (productQty[i] > 0) {
  237.                         System.out.printf("\n\t%s", productList[i]);
  238.                         numOfSpaces = longest - productList[i].length()+3;
  239.                             for (int j = 0; j < numOfSpaces; j++)
  240.                                 System.out.print(" ");
  241.                         System.out.printf("%d\t\t\t\tPHP %.2f", productQty[i], productPrice[i] * productQty[i]);
  242.                     }
  243.                 }
  244.                 System.out.print("\n***********************************************************");
  245.                 System.out.print("\n\t\t\t5% Tax Charge: ");
  246.                 System.out.printf("\t\t\t\tPHP %.2f", taxAmount);
  247.                 System.out.printf("\n\t\t\tAmount Due: \t\t\t\tPHP %.2f", amountDue);
  248.                 System.out.printf("\n\t\t\tTotal Amount To Be Paid: \tPHP %.2f", totalAmount);
  249.                 System.out.printf("\n\t\t\tCASH TENDERED: \t\t\t\tPHP %.2f", cash);
  250.                 System.out.printf("\n\t\t\tChange: \t\t\t\t\tPHP %.2f", change);
  251.                 System.out.print("\n***********************************************************");
  252.                 System.out.print("\n\t\t   This serves as your Official Receipt.");
  253.                 System.out.print("\n***********************************************************");
  254.             }
  255.             else if (cash < totalAmount) {
  256.                 System.out.print("Insufficient Cash. Please try again.\n");
  257.                 continue;
  258.             }
  259.         break;
  260.         }  
  261.     } //End of payment() method
  262.    
  263.     public static void repeatProcess() {       
  264.         System.out.print("\n\n\nEnter 1 to process a new order or 0 to terminate the program.");
  265.         System.out.print("\nEnter your answer: ");
  266.         while (true) {
  267.             if (!write.hasNextInt()) { //Input Mismatch Exception Handler
  268.                 System.out.print("Invalid input. Please try again: ");
  269.                 write.next(); //discard
  270.                 continue;
  271.             }
  272.             inputRepeat = write.nextInt();
  273.             if (inputRepeat == 0) {
  274.                 System.out.print("\nThank you so much!");
  275.                 break;
  276.             }
  277.             else if (inputRepeat != 1 && inputRepeat != 0) {
  278.                 System.out.print("Invalid input. Please try again: ");
  279.                 continue;
  280.             }          
  281.        
  282.         //Reset all ordered products and total amount when the user process a new order
  283.         for (int i = 0; i < numOfProduct; i++) {
  284.             amountDue = 0;             
  285.             productQty[i] = 0;
  286.         }                  
  287.         System.out.println("\n");
  288.         break;
  289.         }  
  290.     } //End of repeatProcess() method
  291.    
  292. } //End of Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement