Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to choose custom sandwiches also did some error handling #12

Merged
merged 2 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/main/java/com/pluralsight/models/BLT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.pluralsight.models;

import java.util.HashSet;
import java.util.Set;

public class BLT extends Sandwich {
public BLT() {
this.setSize("8\"");
this.setType("White");
this.setCheese("Cheddar");
this.setPremiumToppings(new HashSet<>(Set.of("Bacon")));
this.setRegularToppings(new HashSet<>(Set.of("Lettuce", "Tomato")));
this.setSauces(new HashSet<>(Set.of("Ranch")));
this.setToasted(true);
}
}
16 changes: 16 additions & 0 deletions src/main/java/com/pluralsight/models/PhillyCheeseSteak.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.pluralsight.models;

import java.util.HashSet;
import java.util.Set;

public class PhillyCheeseSteak extends Sandwich {
public PhillyCheeseSteak() {
this.setSize("8\"");
this.setType("White");
this.setCheese("American");
this.setPremiumToppings(new HashSet<>(Set.of("Steak")));
this.setRegularToppings(new HashSet<>(Set.of("Peppers")));
this.setSauces(new HashSet<>(Set.of("Mayo")));
this.setToasted(true);
}
}
150 changes: 142 additions & 8 deletions src/main/java/com/pluralsight/userInterfaces/CreateSandwichScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.pluralsight.Utilities.Inputs;
import com.pluralsight.Utilities.Utilities;
import com.pluralsight.models.BLT;
import com.pluralsight.models.Order;
import com.pluralsight.models.PhillyCheeseSteak;
import com.pluralsight.models.Sandwich;

import java.util.*;
Expand All @@ -16,7 +18,24 @@ public CreateSandwichScreen(Order userOrder) {

//Methods

public void sandwichCreationScreen() {
//DISPLAYING MENU CHOICES

public void sandwichCreationHomeScreen() {
Utilities.clearConsole();
System.out.println(Utilities.centerMessage("Choose an option", 45, '-'));
System.out.print("""

[1] Create custom sandwich
[2] Choose a signature sandwich

[x] Cancel sandwich

Enter choice:\s""");

processSandwichHomeScreenMenuChoice();
}

public void customSandwichCreationScreen() {
Sandwich userSandwich = new Sandwich();
boolean isRunning = true;
while (isRunning) {
Expand All @@ -37,11 +56,77 @@ public void sandwichCreationScreen() {

Enter choice:\s""");

isRunning = processSandwichCreationMenuChoice(userSandwich, isRunning);
isRunning = processCustomSandwichCreationMenuChoice(userSandwich, isRunning);
}
}

public void customSandwichCreationScreen(Sandwich userSandwich) {
boolean isRunning = true;
while (isRunning) {
Utilities.clearConsole();
System.out.printf("\n%s\n", userSandwich.displayCurrentSandwich());
System.out.println(Utilities.centerMessage("Customize your sandwich", 45, '-'));
System.out.print("""

[1] Choose bread size
[2] Choose bread type
[3] Choose meats (extra charge)
[4] Choose regular toppings
[5] Choose cheese (only 1 cheese allowed)
[6] Choose sauces

[f] Finalize sandwich
[x] Cancel sandwich

Enter choice:\s""");

isRunning = processCustomSandwichCreationMenuChoice(userSandwich, isRunning);
}
}

private void chooseSignatureSandwichScreen() {
Utilities.clearConsole();
System.out.println("""
Which signature sandwich would you like?

[1] BLT
[2] Philly Cheese Steak

[x] Cancel signature sandwich

Enter choice:\s""");

processSignatureSandwichMenuChoice();
}


//PROCESSING MENU CHOICES
private void processSandwichHomeScreenMenuChoice() {
String userChoice = Inputs.getString();

try {
int userIntChoice = Integer.parseInt(userChoice);
switch (userIntChoice) {
case 1:
customSandwichCreationScreen();
break;
case 2:
chooseSignatureSandwichScreen();
break;
default:
System.out.println("This is not a valid choice, please try again.");
Inputs.awaitInput();
break;
}
} catch (NumberFormatException e) {
switch (userChoice) {
case "X", "x" -> System.out.println();
default -> System.out.println("This is not a valid choice, please try again.");
}
}
}

private boolean processSandwichCreationMenuChoice(Sandwich userSandwich, boolean isRunning) {
private boolean processCustomSandwichCreationMenuChoice(Sandwich userSandwich, boolean isRunning) {
String userChoice = Inputs.getString();

try {
Expand Down Expand Up @@ -110,16 +195,50 @@ private boolean processSandwichCreationMenuChoice(Sandwich userSandwich, boolean
return isRunning;
}

private void processSignatureSandwichMenuChoice() {
String userChoice = Inputs.getString();

try {
int userIntChoice = Integer.parseInt(userChoice);

Sandwich sandwich = null;

switch (userIntChoice) {
case 1:
sandwich = new BLT();
System.out.println(sandwich.displayCurrentSandwich());
break;
case 2:
sandwich = new PhillyCheeseSteak();
System.out.println(sandwich.displayCurrentSandwich());
break;
default:
System.out.println("That's not a valid choice");
Inputs.awaitInput();
break;
}

if (sandwich != null) {
System.out.print("Would you like to edit your sandwich? (Y/N): ");
String editSandwich = Inputs.getString();
if (editSandwich.equalsIgnoreCase("y")) customSandwichCreationScreen(sandwich);
else userOrder.addSandwich(sandwich);
}
} catch (NumberFormatException e) {
if (userChoice.equalsIgnoreCase("x")) System.out.println();
}
}


private void chooseBreadSize(Sandwich userSandwich) {
Utilities.clearConsole();
System.out.println(Utilities.centerMessage("Choosing Bread Size", 50, '='));
System.out.print("\n");
//TODO Need to fix this ??? idk whats wrong.
System.out.print("""
[1] 4" (price)
[2] 6" (price)
[3] 8" (price)
[1] 4" ($5.50)
[2] 8" ($7.00)
[3] 12" ($8.50)

Enter choice:\s""");
int breadSizeChoice = Inputs.getInt();
Expand Down Expand Up @@ -162,7 +281,7 @@ private void chooseBreadType(Sandwich userSandwich) {

private void chooseToppings(Sandwich userSandwich, String type) {
Map<Integer, String> toppings = type.equals("premium") ? userOrder.premiumToppings : userOrder.regularToppings;
Set<String> chosenToppings = new HashSet<>();
Set<String> chosenToppings = checkIfHasToppings(userSandwich, type);

boolean isChoosingToppings = true;
while (isChoosingToppings) {
Expand Down Expand Up @@ -255,7 +374,7 @@ private void chooseCheese(Sandwich userSandwich) {

private void chooseSauces(Sandwich userSandwich) {
Map<Integer, String> sauces = userOrder.sauces;
Set<String> chosenSauces = new HashSet<>();
Set<String> chosenSauces = checkIfHasSauces(userSandwich);
boolean isChoosingSauces = true;
while (isChoosingSauces) {
Utilities.clearConsole();
Expand Down Expand Up @@ -301,6 +420,21 @@ private void chooseSauces(Sandwich userSandwich) {
}
}

private static Set<String> checkIfHasToppings(Sandwich userSandwich, String type) {
Set<String> chosenToppings;
if (type.equalsIgnoreCase("premium") && !userSandwich.getPremiumToppings().isEmpty()) chosenToppings = userSandwich.getPremiumToppings();
else if (type.equalsIgnoreCase("regular") && !userSandwich.getRegularToppings().isEmpty()) chosenToppings = userSandwich.getRegularToppings();
else chosenToppings = new HashSet<>();
return chosenToppings;
}

private Set<String> checkIfHasSauces(Sandwich userSandwich) {
Set<String> sauces;
if (!userSandwich.getSauces().isEmpty()) sauces = userSandwich.getSauces();
else sauces = new HashSet<>();
return sauces;
}

private void displaySummary(Set<String> chosenItems) {
chosenItems.forEach(System.out::println);
}
Expand Down
19 changes: 12 additions & 7 deletions src/main/java/com/pluralsight/userInterfaces/HomeScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
public class HomeScreen {

public static void displayHomeScreen() {
displayWelcomeMessage();
boolean usingApplication = true;
while (usingApplication) {
displayWelcomeMessage();

System.out.print("""
System.out.print("""

[1] Create a new order
[2] View receipts (Admin Only)
Expand All @@ -19,15 +21,16 @@ public static void displayHomeScreen() {

Enter choice:\s""");

processHomeScreenChoice();
usingApplication = processHomeScreenChoice();
}
}

private static void displayWelcomeMessage() {
System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nWelcome to our DELI-cious application");
System.out.println("What can we do for you today?");
}

private static void processHomeScreenChoice() {
private static boolean processHomeScreenChoice() {
int userChoice = Inputs.getInt();

switch (userChoice) {
Expand All @@ -43,13 +46,15 @@ private static void processHomeScreenChoice() {
receipts.forEach(System.out::println);
}
Inputs.awaitInput();
displayHomeScreen();
}
case 0 -> System.exit(0);
case 0 -> {
return false;
}
default -> {
System.out.println("That's not a valid choice, please try again...");
processHomeScreenChoice();
Inputs.awaitInput();
}
}
return true;
}
}
Loading