Skip to content

Instantly share code, notes, and snippets.

@adejaremola
Created May 5, 2020 16:51
Show Gist options
  • Save adejaremola/6d0c061977867e770edf58c9e32515c1 to your computer and use it in GitHub Desktop.
Save adejaremola/6d0c061977867e770edf58c9e32515c1 to your computer and use it in GitHub Desktop.
import java.io.IOException;
import java.util.Scanner;
/**
* Cafe
*/
public class Cafe {
static String inventoryFilePath = "C:/Users/AbdulQudduus/Desktop/Projects/Tayo Codeplus/Java/CoffeeCafe/inventory.txt";
static int menuChoice;
static int transChoice;
static String validateMenu() {
Scanner scanner = new Scanner(System.in);
System.out.print("Choice: ___ ");
try {
menuChoice = scanner.nextInt();
} catch (Exception e) {
System.out.println("Please enter a valid input, between 1 and 6");
validateMenu();
} finally {
if (menuChoice < 1 || menuChoice > 6) {
System.out.println("Please enter a valid input, between 1 and 6");
validateMenu();
}
}
scanner.close();
return "";
}
static String validateTransactionType() {
Scanner scanner = new Scanner(System.in);
System.out.print("Please enter transaction type [1 -- Cash 2 -- Card]: __");
try {
transChoice = scanner.nextInt();
} catch (Exception e) {
e.notify();
System.out.println("Please enter a valid input, between 1 and 2");
validateTransactionType();
} finally {
if (transChoice < 1 || transChoice > 2) {
System.out.println("Please enter a valid input, between 1 and 2");
validateTransactionType();
}
}
scanner.close();
return "";
}
public static void main(String[] args) throws IOException {
Menu menu = new Menu(inventoryFilePath);
System.out.println("\tMENU\n********************");
int i = 1;
for (MenuItem item : menu.getMenu()) {
System.out.println(i + ". " + item.getItemName() + "\t\t" + item.getItemPrice() + "0");
i++;
}
System.out.println(i + ". " + "Exit");
validateMenu();
validateTransactionType();
// if (transChoice == 1) {
// double amtPaid;
// while (true) {
// System.out.print("Please enter amount tendered: __");
// try {
// amtPaid = scanner.nextDouble();
// if (amtPaid < menu.getMenu()[menuChoice - 1].getItemPrice()) {
// System.out.println("Please tender a sufficient amount to cover your bill");
// continue;
// } else {
// break;
// }
// } catch (Exception e) {
// System.out.println("Please enter digits as input");
// }
// scanner.close();
// }
// System.out.println("Here's your " + menu.getMenu()[menuChoice - 1].getItemName() + " and a change of " + (amtPaid - (menu.getMenu()[menuChoice - 1].getItemPrice())));
// }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment