Skip to content

Commit

Permalink
Slight tweaks to access, uncomments login
Browse files Browse the repository at this point in the history
  • Loading branch information
conor-walker committed Apr 11, 2021
1 parent d48d54e commit 1e34177
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
55 changes: 28 additions & 27 deletions src/main/java/Display.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,46 @@ public class Display {
private static final Books currentStock = new Books(new ReadDelimitedFile());
private static final List<Book> stock = currentStock.getAllInventory();

public static void mainMenu(){
public static void menuLoop (){
do {
mainMenu();
int selection = userInt(1,4);
switch(selection){
case(1):
selectItem();
break;
case(2):
System.out.println(currentCart.toString());
break;
case(3):
currentCart.checkoutBasket();
leaveStore();
case(4):
leaveStore();
default:
System.out.println("Invalid selection - please try again!" +"\n");
}
} while(true);
}


private static void mainMenu(){
System.out.println("Please select your option:");
System.out.println("1: View books");
System.out.println("2: View Cart");
System.out.println("3: Checkout");
System.out.println("4: Logout");
}

public static void displayItems(){
private static void displayItems(){
int id = 1;
for (Book book : stock) {
System.out.println(id + ": " + book.toString());
id++;
}
}

public static int userInt(int lowerBound,int upperBound){
private static int userInt(int lowerBound,int upperBound){
int selection;
do{
while (!userInput.hasNextInt()){
Expand All @@ -39,37 +62,15 @@ public static int userInt(int lowerBound,int upperBound){
return selection;
}

public static void selectItem(){
private static void selectItem(){
displayItems();
System.out.println("Please select an item to buy:");
int selection = userInt(0,stock.size());
currentCart.addToBasket(stock.get(selection - 1));
System.out.println("Item added!\n");
}

public static void menuLoop (){
do {
mainMenu();
int selection = userInt(1,4);
switch(selection){
case(1):
selectItem();
break;
case(2):
System.out.println(currentCart.toString());
break;
case(3):
currentCart.checkoutBasket();
leaveStore();
case(4):
leaveStore();
default:
System.out.println("Invalid selection - please try again!" +"\n");
}
} while(true);
}

public static void leaveStore(){
private static void leaveStore(){
System.out.println("Thanks for shopping!");
System.exit(0);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class Main {
public static void main(String[] args){
Customers registeredUsers = new CustomersFromFile();
Authorisation logIn = new Login(registeredUsers);
//logIn.logIn();
logIn.logIn();
Display.menuLoop();
}
}

0 comments on commit 1e34177

Please sign in to comment.