Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Java by Zomer ( 7 years ago )
import java.text.SimpleDateFormat;
import java.util.*;
//import java.io.IOException;

public class ZomerPOSfinale{
	//Date, receipt#, & scanner - START
	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); // END
	
	//Product lists, prices, default quantities, etc. - START
	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 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                   0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                   0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                   0, 0, 0, 0, 0};
                                   
	static double taxPercent = 0.12d, amountDue, cash, change = cash - amountDue;
	static String customerName;
	static int inputRepeat; // END		
	static int longest = 0; //longest character in productList
	private static Scanner scanName = new Scanner(System.in);
	
	public static void main(String[] args) {
		do {
			menu();
			getOrder();
			reviewOrders();
			payment();
			repeatProcess();
			//cls();
		} 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\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 - START
		System.out.print("\n----------------------------------------------------------");
		System.out.print("\n\t\t| MEALS |");
		System.out.print("\n----------------------------------------------------------");
		for (int i = 0; i < 9; i++) { // 0 -8 [array] PL
			System.out.printf("\n [0%d]\t\t%s", i+1, productList[i]);
			int numOfSpaces = longest - productList[i].length() +2;
				for (int j = 0; j < numOfSpaces; j++) 
					System.out.print(" ");
			System.out.printf("\t\u20B1%.2f", productPrice[i]);
		}
		for (int i = 9; i < 15; i++) { // 9 - 14 [array] PL
			System.out.printf("\n [%d]\t\t%s", i+1, productList[i]);
			int numOfSpaces = longest - productList[i].length() +2;
				for (int j = 0; j < numOfSpaces; j++) 
					System.out.print(" ");
			System.out.printf("\t\u20B1%.2f", productPrice[i]); // END
		}
		//Desserts - START
		System.out.print("\n----------------------------------------------------------");
		System.out.print("\n\t\t| DESSERTS |");
		System.out.print("\n----------------------------------------------------------");
		for (int i = 15; i < 25; i++) { // 15 - 24 [array] PL
			System.out.printf("\n [%d]\t\t%s", i+1, productList[i]);
			int numOfSpaces = longest - productList[i].length() +2;
				for (int j = 0; j < numOfSpaces; j++) 
					System.out.print(" ");
			System.out.printf("\t\u20B1%.2f", productPrice[i]); // END
		}
		//Drinks - START
		System.out.print("\n----------------------------------------------------------");
		System.out.print("\n\t\t| DRINKS |");
		System.out.print("\n----------------------------------------------------------");
		for (int i = 25; i < 35; i++) { // 25 - 34 [array] PL
			System.out.printf("\n [%d]\t\t%s", i+1, productList[i]);
			int numOfSpaces = longest - productList[i].length() +2;
				for (int j = 0; j < numOfSpaces; j++) 
					System.out.print(" ");
			System.out.printf("\t\u20B1%.2f", productPrice[i]); // END
		}
		System.out.print("\n----------------------------------------------------------");
		System.out.print("\nEnter product code & quantity to place the order.");
		System.out.print("\nEnter 0[zero] to product code if you wish to review \nor 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()){ //Mismatch Exception Handler
				System.out.print("Please enter a valid product code.");
				write.next(); //discard
				continue;
			}
			code = write.nextInt();
		
		// Execute loop if user enters below 0 or above product code		
			if (code < 0 ||  code > numOfProduct) {
				System.out.print("Please enter a valid product code.");
				continue;
			}
			 else if (code == 0)
			 break;
		while (true) {
			System.out.print("Enter Product Quantity: ");				
			if (!write.hasNextInt()) { //Mismatch Exception Handler
				System.out.print("Please enter valid quantity.\n");
				write.next(); //discard
				continue;
			}
			qty = write.nextInt();
			productQty[code-1] += qty;
		
		// Execute loop if user enters 0 or below to quantity
			if (productQty[code-1] <= 0) {
				System.out.println("Please enter valid quantity.");
				productQty[code-1] = 0;						
			} else 
			break;
			}
		}
	} //End of getOrder() method
	
	public static void reviewOrders() {
		while (true) {
			System.out.print("\nReview Order(s): ");
			// Longest character in productlist
			for (int i = 0; i < numOfProduct; i++)
				if (longest < productList[i].length())
					 longest = productList[i].length();
					 				 
			// Display & review ordered products & total amount to be paid
			for (int i = 0; i < numOfProduct; i++) {
				if (productQty[i] > 0) {
					System.out.printf("\nCode %d\t%s", i+1, productList[i]);
					int numOfSpaces = longest - productList[i].length()+3;
						for (int j = 0; j < numOfSpaces; j++) 
							System.out.print(" ");
					System.out.printf("Qty: %d\t Subtotal: \u20B1%.2f", productQty[i], productPrice[i] * productQty[i]);
				}
			}
			for (int i = 0; i < numOfProduct; i++) {
				amountDue += productPrice[i] * productQty[i];	
			}		
			double taxAmount = amountDue * taxPercent;
			double totalAmount = amountDue + taxAmount;
			System.out.printf("\n\nAmount Due: \t\t\u20B1%.2f", amountDue);
			System.out.print("\n12% Tax Charge: ");
			System.out.printf("\t\u20B1%.2f", taxAmount);
			System.out.printf("\nTotal Amount: \t\t\u20B1%.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()) { //Mismatch Exception Handler
					System.out.print("Please enter a valid answer: ");
					write.next(); //discard
					continue;
				}
				int orderAns = write.nextInt();
				if (orderAns == 1) {
					return;
				}
				else if (orderAns == 0) {
					getOrder();
				} 
				else {
					System.out.print("Please enter a valid answer: ");
					continue;
				}
			break;
			}	
		}
	} //End of reviewOrders() method
	
	public static void payment() {
		double taxAmount = amountDue * taxPercent;
		double totalAmount = amountDue + taxAmount;
		//Longest
		for (int i = 0; i < numOfProduct; i++)	
			if (longest < productList[i].length())
				 longest = productList[i].length();	
		
		// GETTING USER NAME & CASH
		System.out.print("\n\nPayment");
		System.out.print("\nPlease enter your name: ");
		customerName = scanName.nextLine();			
		while (true) {					
			System.out.print("Enter Cash: \u20B1");				
			if (!write.hasNextDouble()){ //Mismatch Exception Handler
				System.out.print("Please enter a valid amount.\n");
				write.next(); //discard
				continue;
			}
			cash = write.nextDouble();
			if (cash >= totalAmount) {
				double change = cash - totalAmount;
			
				// DISPLAY RECEIPT
				System.out.print("\n\n\n***********************************************************");
				System.out.print("\n\t\tZomer's Unlirice Restaurant");
				System.out.print("\n\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\tQuantity\tSubtotal");
				for (int i = 0; i < numOfProduct; i++) {
					if (productQty[i] > 0) {
						System.out.printf("\n\t%s", productList[i]);
						int numOfSpaces = longest - productList[i].length()+3;
							for (int j = 0; j < numOfSpaces; j++) 
								System.out.print(" ");
						System.out.printf("\t%d\t\t\u20B1%.2f", productQty[i], productPrice[i] * productQty[i]);
					}
				}
				System.out.print("\n***********************************************************");
				System.out.print("\n\t\t12% Tax Charge: ");
				System.out.printf("\t\t\u20B1%.2f", amountDue * taxPercent);
				System.out.printf("\n\t\tAmount Due: \t\t\t\u20B1%.2f", amountDue);
				System.out.printf("\n\t\tTotal Amount To Be Paid: \t\u20B1%.2f", totalAmount);
				System.out.printf("\n\t\tCASH TENDERED: \t\t\t\u20B1%.2f", cash);
				System.out.printf("\n\t\tChange: \t\t\t\u20B1%.2f", change);
				System.out.print("\n***********************************************************");
				System.out.print("\n\t  This serves as your Official Receipt.");
				System.out.print("\n***********************************************************");
				//System.out.print("\n\n\n\t\t\t12% VAT INCLUDED");
			}
			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()) { //Mismatch Exception Handler
				System.out.print("Please enter a valid answer: ");
				write.next(); //discard
				continue;
			} 
			inputRepeat = write.nextInt(); 
			if (inputRepeat == 0) {
				System.out.print("\nThank you, come again.");
				break;
			}
			else if (inputRepeat == 1) {
				//System.out.print("\033[H\033[2J"); //clear command screen
				System.out.flush();
			}
			else if (inputRepeat != 1 && inputRepeat != 0) {
				System.out.print("Please enter a valid answer: ");
				continue;
			}			
		
		// Reset all ordered products and total 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
	
	/** public static void cls() {
		try {
			new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
		} catch(Exception E) {
			System.out.println(E);
		}			
		System.out.print("\033[H\033[2J"); //clear command screen
		System.out.flush();
	} **/
	
} //End of Class

 

Revise this Paste

Your Name: Code Language: