Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- Name: Zomer L. Gregorio
- Course & Section: BSIT 112
- Subject: Computer Programming 1
- Teacher: Jerome Austria
- **/
- import java.text.SimpleDateFormat;
- import java.util.*;
- public class ZomerPOS {
- //Date, receipt#, & scanner
- final static Date currentTime = new Date();
- final static SimpleDateFormat sdf = new SimpleDateFormat("EEE, MMM d, yyyy");
- final static SimpleDateFormat receipt = new SimpleDateFormat("yyyyMMddHHmmss");
- static Scanner write = new Scanner(System.in);
- //Product lists, prices, default quantities, etc.
- static int numOfProduct = 35;
- final static String[] productList = {"Chicken Adobo", "Chicken Inasal", "Chicken Curry",
- "Chicken Teriyaki", "Fried Chicken", "Pork Adobo",
- "Pork Sisig", "Lechon Kawali", "Lechon Paksiw",
- "Sinigang", "Beef Caldereta", "Beef Steak",
- "Beef Kare-Kare", "Beef Mechado", "Bulalo",
- "Cassava Cake", "Buko Pandan Salad", "Fruit Salad",
- "Ginataang Bilo-Bilo", "Macaroni Salad", "Pichi-Pichi",
- "Ube Halaya", "Ice Cream", "Leche Flan", "Halo-Halo",
- "Coke", "Sprite", "Royal", "Orange Juice", "Mango Juice",
- "Lemon Ice Tea", "Fruit Safari", "Calamansi Slushie",
- "Pink Lemonade", "Mint Jito"};
- final static double[] productPrice = {130, 130, 135, 125, 125, 130, 120, 125, 130, 120,
- 130, 135, 135, 130, 120, 40, 50, 50, 30, 50,
- 40, 40, 40, 60, 40, 15, 15, 15, 20, 20,
- 20, 90, 80, 110, 120};
- static int[] productQty = new int[35];
- static double taxPercent = 0.05d, amountDue, cash, change, taxAmount, totalAmount;
- static String customerName;
- static int inputRepeat; //Input for repeating the program
- static int longest = 0, numOfSpaces; //longest character in productList
- private static Scanner scanName = new Scanner(System.in);
- public static void main(String[] args) {
- do {
- menu();
- getOrder();
- reviewOrders();
- payment();
- repeatProcess();
- } while (inputRepeat == 1);
- }
- public static void menu() {
- //Get length of longest character in productList for display alignment
- for (int i = 0; i < numOfProduct; i++)
- if (longest < productList[i].length())
- longest = productList[i].length();
- // Display menu
- System.out.print("----------------------------------------------------------");
- System.out.print("\n\t\t\tZOMER'S UNLIRICE RESTAURANT \t\t");
- System.out.print("\n\t Welcome! Please choose your order.\t");
- System.out.print("\n----------------------------------------------------------");
- System.out.print("\n CODE\t\tPRODUCT\t\t\tPRICE");
- System.out.print("\n\t\t\t\t");
- //Meal
- System.out.print("\n----------------------------------------------------------");
- System.out.print("\n\t\t\t| MEALS |");
- System.out.print("\n----------------------------------------------------------");
- for (int i = 0; i < 9; i++) { //productList [0-8]
- System.out.printf("\n [0%d]\t\t%s", i+1, productList[i]);
- numOfSpaces = longest - productList[i].length() +2;
- for (int j = 0; j < numOfSpaces; j++)
- System.out.print(" ");
- System.out.printf("\tPHP %.2f", productPrice[i]);
- }
- for (int i = 9; i < 15; i++) { //productList [9-14]
- System.out.printf("\n [%d]\t\t%s", i+1, productList[i]);
- numOfSpaces = longest - productList[i].length() +2;
- for (int j = 0; j < numOfSpaces; j++)
- System.out.print(" ");
- System.out.printf("\tPHP %.2f", productPrice[i]);
- }
- //Desserts
- System.out.print("\n----------------------------------------------------------");
- System.out.print("\n\t\t\t| DESSERTS |");
- System.out.print("\n----------------------------------------------------------");
- for (int i = 15; i < 25; i++) { //productList [15-24]
- System.out.printf("\n [%d]\t\t%s", i+1, productList[i]);
- numOfSpaces = longest - productList[i].length() +2;
- for (int j = 0; j < numOfSpaces; j++)
- System.out.print(" ");
- System.out.printf("\tPHP %.2f", productPrice[i]);
- }
- //Drinks
- System.out.print("\n----------------------------------------------------------");
- System.out.print("\n\t\t\t| DRINKS |");
- System.out.print("\n----------------------------------------------------------");
- for (int i = 25; i < 35; i++) { //productList [25-34]
- System.out.printf("\n [%d]\t\t%s", i+1, productList[i]);
- numOfSpaces = longest - productList[i].length() +2;
- for (int j = 0; j < numOfSpaces; j++)
- System.out.print(" ");
- System.out.printf("\tPHP %.2f", productPrice[i]); // END
- }
- System.out.print("\n----------------------------------------------------------");
- System.out.print("\nEnter product code & quantity to place the order.");
- System.out.print("\nEnter negative number to quantity to delete the product(s) you ordered.");
- System.out.print("\nEnter 0[zero] to product code if you wish to review or finish your order(s).\n");
- } //End of menu() method
- public static void getOrder() {
- int code, qty;
- while (true) {
- System.out.print("\nEnter Product Code: ");
- if (!write.hasNextInt()){ //Input Mismatch Exception Handler
- System.out.print("Invalid product code. Please try again.");
- write.next(); //discard
- continue;
- }
- code = write.nextInt();
- if (code > 0 && code < 16) {
- System.out.print("Meal: " + productList[code-1] + "\n");
- }
- else if (code > 15 && code < 26) {
- System.out.print("Dessert: " + productList[code-1] + "\n");
- }
- else if (code > 25 && code < 36) {
- System.out.print("Drink: " + productList[code-1] + "\n");
- }
- //Execute loop if user enters below 0 or above product code
- else if (code < 0 || code > numOfProduct) {
- System.out.print("Invalid product code. Please try again.");
- continue;
- }
- else if (code == 0)
- break;
- while (true) {
- System.out.print("Enter Product Quantity: ");
- if (!write.hasNextInt()) { //Input Mismatch Exception Handler
- System.out.print("Invalid input. Please try again.\n");
- write.next(); //discard
- continue;
- }
- qty = write.nextInt();
- if (qty > 0) {
- productQty[code-1] += qty;
- }
- else if (qty == 0) {
- System.out.print("Cancelled.\n");
- }
- //Deleted ordered products
- else if (qty < 0 && productQty[code-1] >= Math.abs(qty)) {
- productQty[code-1] -= Math.abs(qty);
- System.out.print(productList[code-1] + ": " + Math.abs(qty) + " quantity deleted.\n");
- }
- else if (qty < 0 && productQty[code-1] < Math.abs(qty)) {
- System.out.print("Not enough quantites to be deleted. ");
- System.out.print("Please try again.\n");
- continue;
- }
- break;
- }
- }
- } //End of getOrder() method
- public static void reviewOrders() {
- while (true) {
- // Display & review ordered products & total amount to be paid
- System.out.print("\nReview Order(s): ");
- for (int i = 0; i < numOfProduct; i++) {
- if (productQty[i] > 0) {
- System.out.printf("\nCode %d\t%s", i+1, productList[i]);
- numOfSpaces = longest - productList[i].length()+3;
- for (int j = 0; j < numOfSpaces; j++)
- System.out.print(" ");
- System.out.printf("Qty: %d\t Subtotal: PHP %.2f", productQty[i], productPrice[i] * productQty[i]);
- }
- }
- for (int i = 0; i < numOfProduct; i++) {
- amountDue += productPrice[i] * productQty[i]; //Computation of amountDue
- }
- taxAmount = amountDue * taxPercent;
- totalAmount = amountDue + taxAmount; //Total amount to be paid
- System.out.printf("\n\nAmount Due: \t\tPHP %.2f", amountDue);
- System.out.print("\n5% Tax Charge: ");
- System.out.printf("\t\tPHP %.2f", taxAmount);
- System.out.printf("\nTotal Amount: \t\tPHP %.2f", totalAmount);
- System.out.print("\n-----------------------------------------------------------");
- System.out.print("\nDo you want to finish your order?\nEnter 1 for Yes or 0 for No: ");
- while (true) {
- if (!write.hasNextInt()) { //Input Mismatch Exception Handler
- System.out.print("Please enter 1 or 0 only: ");
- write.next(); //discard
- continue;
- }
- int orderAns = write.nextInt();
- if (orderAns == 1) {
- return;
- }
- else if (orderAns == 0) {
- getOrder();
- }
- else {
- System.out.print("Please enter 1 or 0 only: ");
- continue;
- }
- break;
- }
- }
- } //End of reviewOrders() method
- public static void payment() {
- // Getting customer name & cash
- System.out.print("\n\nPayment");
- System.out.print("\nPlease enter your name: ");
- customerName = scanName.nextLine();
- while (true) {
- System.out.print("Enter Cash: PHP ");
- if (!write.hasNextDouble()){ //Input Mismatch Exception Handler
- System.out.print("Please enter a valid amount.\n");
- write.next(); //discard
- continue;
- }
- cash = write.nextDouble();
- if (cash >= totalAmount) {
- change = cash - totalAmount;
- //Print receipt
- System.out.print("\n\n\n***********************************************************");
- System.out.print("\n\t\t\t\tZomer's Unlirice Restaurant");
- System.out.print("\n\t\t\t\t Alabang, Muntinlupa City");
- System.out.print("\n***********************************************************");
- System.out.print("\nReceipt #: " + receipt.format(currentTime));
- System.out.print("\nDate: " + sdf.format(currentTime));
- System.out.print("\nCustomer Name: " + customerName);
- System.out.print("\n***********************************************************");
- System.out.print("\nORDER: \n\tProduct\t\t\t\tQuantity\t\tSubtotal");
- for (int i = 0; i < numOfProduct; i++) {
- if (productQty[i] > 0) {
- System.out.printf("\n\t%s", productList[i]);
- numOfSpaces = longest - productList[i].length()+3;
- for (int j = 0; j < numOfSpaces; j++)
- System.out.print(" ");
- System.out.printf("%d\t\t\t\tPHP %.2f", productQty[i], productPrice[i] * productQty[i]);
- }
- }
- System.out.print("\n***********************************************************");
- System.out.print("\n\t\t\t5% Tax Charge: ");
- System.out.printf("\t\t\t\tPHP %.2f", taxAmount);
- System.out.printf("\n\t\t\tAmount Due: \t\t\t\tPHP %.2f", amountDue);
- System.out.printf("\n\t\t\tTotal Amount To Be Paid: \tPHP %.2f", totalAmount);
- System.out.printf("\n\t\t\tCASH TENDERED: \t\t\t\tPHP %.2f", cash);
- System.out.printf("\n\t\t\tChange: \t\t\t\t\tPHP %.2f", change);
- System.out.print("\n***********************************************************");
- System.out.print("\n\t\t This serves as your Official Receipt.");
- System.out.print("\n***********************************************************");
- }
- else if (cash < totalAmount) {
- System.out.print("Insufficient Cash. Please try again.\n");
- continue;
- }
- break;
- }
- } //End of payment() method
- public static void repeatProcess() {
- System.out.print("\n\n\nEnter 1 to process a new order or 0 to terminate the program.");
- System.out.print("\nEnter your answer: ");
- while (true) {
- if (!write.hasNextInt()) { //Input Mismatch Exception Handler
- System.out.print("Invalid input. Please try again: ");
- write.next(); //discard
- continue;
- }
- inputRepeat = write.nextInt();
- if (inputRepeat == 0) {
- System.out.print("\nThank you so much!");
- break;
- }
- else if (inputRepeat != 1 && inputRepeat != 0) {
- System.out.print("Invalid input. Please try again: ");
- continue;
- }
- //Reset all ordered products and total amount when the user process a new order
- for (int i = 0; i < numOfProduct; i++) {
- amountDue = 0;
- productQty[i] = 0;
- }
- System.out.println("\n");
- break;
- }
- } //End of repeatProcess() method
- } //End of Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement