Skip to content

Commit

Permalink
Merge pull request #17 from sekwanaa/refactoring
Browse files Browse the repository at this point in the history
Refactored code to remove misused try-catch blocks and to replace while loops with recursion
  • Loading branch information
sekwanaa committed May 29, 2024
2 parents ff49baf + 859a62e commit be76e73
Show file tree
Hide file tree
Showing 16 changed files with 881 additions and 903 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/pluralsight/Main.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.pluralsight;

import com.pluralsight.Utilities.Inputs;
import com.pluralsight.userInterfaces.HomeScreen;
import com.pluralsight.util.Inputs;
import com.pluralsight.ui.HomeScreen;

public class Main {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.pluralsight.Constants;
package com.pluralsight.constants;

public enum AdminPasswords {
RECEIPT_LOGS("receiptAdmin123!");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.pluralsight.DataManagers;
package com.pluralsight.dataManagers;

import com.pluralsight.Constants.AdminPasswords;
import com.pluralsight.Utilities.Inputs;
import com.pluralsight.Utilities.Utilities;
import com.pluralsight.constants.AdminPasswords;
import com.pluralsight.util.Inputs;
import com.pluralsight.util.Text;

import java.io.*;
import java.time.LocalDate;
Expand Down Expand Up @@ -57,7 +57,7 @@ private static String viewReceiptLog(File file) {
}

private static boolean verifyPassword() {
Utilities.clearConsole();
Text.clearConsole();
System.out.print("Enter Password: ");
String userInput = Inputs.getString();
return userInput.equals(AdminPasswords.RECEIPT_LOGS.password);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/pluralsight/models/Chips.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.pluralsight.models;

import com.pluralsight.models.abstractModel.Product;

public class Chips extends Product {
private String name;

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/pluralsight/models/Drinks.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.pluralsight.models;

import com.pluralsight.models.abstractModel.Product;

public class Drinks extends Product {
private String brand;
private String size;
Expand Down
99 changes: 52 additions & 47 deletions src/main/java/com/pluralsight/models/Order.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.pluralsight.models;

import com.pluralsight.Utilities.Utilities;
import com.pluralsight.util.Text;

import java.util.*;

Expand All @@ -17,60 +17,65 @@ public Order() {
this.sidesList = new ArrayList<>();
}

public final Map<Integer, String> sides = new TreeMap<>(Map.of(
1, "au jus",
2, "sauce"
public final Map<String, String> premiumToppings = new TreeMap<>(Map.of(
"1", "Steak",
"2", "Ham",
"3", "Salami",
"4", "Roast Beef",
"5", "Chicken",
"6", "Bacon"
));

public final Map<Integer, String> premiumToppings = new TreeMap<>(Map.of(
1, "Steak",
2, "Ham",
3, "Salami",
4, "Roast Beef",
5, "Chicken",
6, "Bacon"
public final Map<String, String> regularToppings = new TreeMap<>(Map.of(
"1", "Lettuce",
"2", "Peppers",
"3", "Onions",
"4", "Tomatoes",
"5", "Jalapenos",
"6", "Cucumbers",
"7", "Pickles",
"8", "Guacamole",
"9", "Mushrooms"
));

public final Map<Integer, String> regularToppings = new TreeMap<>(Map.of(
1, "Lettuce",
2, "Peppers",
3, "Onions",
4, "Tomatoes",
5, "Jalapenos",
6, "Cucumbers",
7, "Pickles",
8, "Guacamole",
9, "Mushrooms"
public final Map<String, String> sauces = new TreeMap<>(Map.of(
"1", "Mayo",
"2", "Mustard",
"3", "Ketchup",
"4", "Ranch",
"5", "Thousand Islands",
"6", "Vinaigrette"

));

public final Map<String, String> drinksList = new TreeMap<>(Map.of(
"1", "Coke",
"2", "Root Beer",
"3", "Pepsi",
"4", "Dr. Pepper",
"5", "Fanta",
"6", "Lemonade"
));

public final Map<String, String> chipsList = new TreeMap<>(Map.of(
"1", "Kettle Cooked Jalapeno",
"2", "Lays Classic",
"3", "Cheetos",
"4", "Doritos Cool Ranch",
"5", "Doritos Nacho Cheese"
));

public final Map<String, String> sides = new TreeMap<>(Map.of(
"1", "au jus",
"2", "sauce"
));

public final Map<Integer, String> cheeses = new TreeMap<>(Map.of(
1, "American",
2, "Provolone",
3, "Cheddar",
4, "Swiss"
));
public final Map<Integer, String> sauces = new TreeMap<>(Map.of(
1, "Mayo",
2, "Mustard",
3, "Ketchup",
4, "Ranch",
5, "Thousand Islands",
6, "Vinaigrette"
));
public final Map<Integer, String> drinksList = new TreeMap<>(Map.of(
1, "Coke",
2, "Root Beer",
3, "Pepsi",
4, "Dr. Pepper",
5, "Fanta",
6, "Lemonade"
));
public final Map<Integer, String> chipsList = new TreeMap<>(Map.of(
1, "Kettle Cooked Jalapeno",
2, "Lays Classic",
3, "Cheetos",
4, "Doritos Cool Ranch",
5, "Doritos Nacho Cheese"
));


//Methods
Expand Down Expand Up @@ -125,7 +130,7 @@ public String toString() {
}

if (!this.drinks.isEmpty()) {
output.append(Utilities.createHeader("Drinks"));
output.append(Text.createHeader("Drinks"));
String drinkAbbrev = "";
for (Drinks drink : drinks) {
switch (drink.getSize()) {
Expand All @@ -139,7 +144,7 @@ public String toString() {
}

if (!this.chips.isEmpty()) {
output.append((Utilities.createHeader("Chips")));
output.append((Text.createHeader("Chips")));
for (Chips chips : chips) {
double chipsCost = chips.getPrice();
subtotal += chipsCost;
Expand All @@ -150,7 +155,7 @@ public String toString() {
}

if (!this.sidesList.isEmpty()) {
output.append(Utilities.createHeader("Sides"));
output.append(Text.createHeader("Sides"));
sidesList.forEach(side -> output.append(String.format(" %s\n", side.getName())));
}

Expand Down
39 changes: 35 additions & 4 deletions src/main/java/com/pluralsight/models/Sandwich.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.pluralsight.models;

import com.pluralsight.Utilities.Utilities;
import com.pluralsight.models.abstractModel.Product;
import com.pluralsight.util.Text;

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

public class Sandwich extends Product {
Expand All @@ -10,11 +12,31 @@ public class Sandwich extends Product {
private Set<String> premiumToppingsList;
private boolean extraMeat = false;
private Set<String> regularToppingsList;
private final Set<String> toppingsToAdd = new HashSet<>();
private String cheese;
private boolean extraCheese = false;
private Set<String> saucesList;
private final Set<String> saucesToAdd = new HashSet<>();
private boolean toasted = false;

//METHODS

public void addToppings(String topping) {
this.toppingsToAdd.add(topping);
}

public void clearToppingsToAdd() {
this.toppingsToAdd.clear();
}

public void addSauces(String sauce) {
this.saucesToAdd.add(sauce);
}

public void clearSaucesToAdd() {
this.saucesToAdd.clear();
}

public double getPrice() {
double finalPrice = 0;
double premiumToppingCharge = 0;
Expand Down Expand Up @@ -105,10 +127,18 @@ public void setRegularToppings(Set<String> regularToppings) {
this.regularToppingsList = regularToppings;
}

public Set<String> getToppingsToAdd() {
return this.toppingsToAdd;
}

public Set<String> getSauces() {
return saucesList;
}

public Set<String> getSaucesToAdd() {
return saucesToAdd;
}

public void setSauces(Set<String> sauces) {
this.saucesList = sauces;
}
Expand Down Expand Up @@ -155,7 +185,7 @@ public String toString() {
String cheese = getCheese() != null ? getCheese() : "N/A";
String sandwichInfo = String.format("Sandwich [%s %s]", getSize(), getType());

output.append(" ").append(Utilities.createHeader(sandwichInfo, getPrice()));
output.append(" ").append(Text.createHeader(sandwichInfo, getPrice()));
output.append(String.format("""
Cheese: %s
Toasted: %s | Extra Cheese: %s | Extra Meat: %s
Expand Down Expand Up @@ -185,7 +215,7 @@ public String toString() {
}

public String displayCurrentSandwich() {
return Utilities.centerMessage("Your current sandwich", 45, '-') +
return Text.centerMessage("Your current sandwich", 45, '-') +
"\n\n" +
String.format("Bread Size: %s | Bread Type: %s\n", (getSize() == null ? "Required" : getSize()), (getType() == null ? "Required" : getType())) +
"Meats: " +
Expand All @@ -207,7 +237,7 @@ public String displayCurrentSandwichCompact(int sandwichNum) {
String cheese = getCheese() != null ? getCheese() : "N/A";
String sandwichInfo = String.format("Sandwich %d [%s %s]", sandwichNum, getSize(), getType());

output.append(" ").append(Utilities.createHeader(sandwichInfo, getPrice()));
output.append(" ").append(Text.createHeader(sandwichInfo, getPrice()));
output.append(String.format("""
Cheese: %s
Toasted: %s | Extra Cheese: %s | Extra Meat: %s
Expand Down Expand Up @@ -235,4 +265,5 @@ public String displayCurrentSandwichCompact(int sandwichNum) {
}
return output.toString();
}

}
2 changes: 2 additions & 0 deletions src/main/java/com/pluralsight/models/Sides.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.pluralsight.models;

import com.pluralsight.models.abstractModel.Product;

public class Sides extends Product {
private String name;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.pluralsight.models;
package com.pluralsight.models.abstractModel;

public abstract class Product {
@Override
Expand Down
Loading

0 comments on commit be76e73

Please sign in to comment.