Instruction go brrrr.
This commit is contained in:
@@ -8,78 +8,20 @@ public class RecipeInstructions
|
|||||||
{
|
{
|
||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
{
|
{
|
||||||
int usrChoice;
|
String userInstruction;
|
||||||
|
|
||||||
ArrayList<RecipeNode> ingredients = new ArrayList<>();
|
ArrayList<RecipeNode> ingredients = new ArrayList<>();
|
||||||
RecipeTree fullInstructions = new RecipeTree();
|
RecipeTree fullInstructions = new RecipeTree();
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
Scanner userOption = new Scanner(System.in);
|
System.out.println("Enter instruction: ");
|
||||||
|
Scanner userInput = new Scanner(System.in);
|
||||||
|
userInstruction = userInput.nextLine();
|
||||||
|
|
||||||
System.out.println("What would you like to do?\n1.Add Ingredient\n2.Mix");
|
RecipeCreation(userInstruction);
|
||||||
usrChoice = userOption.nextInt();
|
|
||||||
|
|
||||||
// Switch case for user's choice
|
} while (userInstruction.equalsIgnoreCase("done"));
|
||||||
switch (usrChoice)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
// Init 3 scanners because usually scanners crash on me with multiple input types lmao
|
|
||||||
Scanner ingredientAddAmount = new Scanner(System.in); // Init Scanner for Added amount
|
|
||||||
Scanner ingredientAddName = new Scanner(System.in); // Init Another Scanner for Name
|
|
||||||
Scanner ingredientAddPortion = new Scanner(System.in); // Init Yet another Scanner for Portion
|
|
||||||
|
|
||||||
System.out.print("Enter how many ingredients you're adding: ");
|
|
||||||
int amountIngredient = ingredientAddAmount.nextInt(); // Defining how many ingredients will be added
|
|
||||||
|
|
||||||
for (int i = 0; i < amountIngredient; i++)
|
|
||||||
{
|
|
||||||
// Getting Ingredient Name
|
|
||||||
System.out.println("Enter ingredient Name");
|
|
||||||
String ingredientName = ingredientAddName.nextLine();
|
|
||||||
|
|
||||||
// Getting Ingredient Portion size
|
|
||||||
System.out.println("\nEnter ingredient portion");
|
|
||||||
double ingredientPortion = ingredientAddPortion.nextDouble();
|
|
||||||
|
|
||||||
// Creating the Ingredient's node and putting it into array list
|
|
||||||
// for safe keeping and later use
|
|
||||||
RecipeNode newIngredient = new RecipeNode(ingredientName, ingredientPortion);
|
|
||||||
// fullInstructions.addNode((RecipeNode) null, newIngredient);
|
|
||||||
ingredients.add(newIngredient);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
Scanner ingredientNames = new Scanner(System.in); // Scanner for ingredients' names
|
|
||||||
String userIngredients; // String poo
|
|
||||||
ArrayList<RecipeNode> bowl = new ArrayList<>(); // Mixing bowl for ingredients obviously
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
System.out.println("Enter ingredient names to be mixed (type done to exit)");
|
|
||||||
userIngredients = ingredientNames.nextLine();
|
|
||||||
|
|
||||||
for (RecipeNode ingredient : ingredients)
|
|
||||||
{
|
|
||||||
if (userIngredients.equals(ingredient.getIngredient()))
|
|
||||||
{
|
|
||||||
bowl.add(ingredient);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} while (!userIngredients.equalsIgnoreCase("done"));
|
|
||||||
|
|
||||||
RecipeNode mixture = new RecipeNode(bowl.get(0) + " mix", 69);
|
|
||||||
ingredients.add(mixture);
|
|
||||||
|
|
||||||
for (RecipeNode childIngredient : bowl)
|
|
||||||
{
|
|
||||||
mixture.addChild(childIngredient);
|
|
||||||
childIngredient.parent = mixture;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
} while (usrChoice != -1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Magical Regex
|
//Magical Regex
|
||||||
@@ -96,7 +38,7 @@ public class RecipeInstructions
|
|||||||
RecipeTree fullInstructions = new RecipeTree();
|
RecipeTree fullInstructions = new RecipeTree();
|
||||||
//Stinky Scanner please remove or something idk
|
//Stinky Scanner please remove or something idk
|
||||||
//Maybe make the method take a string in or somethiong :D
|
//Maybe make the method take a string in or somethiong :D
|
||||||
Scanner input = new Scanner(System.in);
|
// Scanner input = new Scanner(System.in); <-- Commented remove for testing
|
||||||
String userInput;
|
String userInput;
|
||||||
//Need to not hardcode verbs maybe a global variable for it? etc etc
|
//Need to not hardcode verbs maybe a global variable for it? etc etc
|
||||||
String[] verbs = {"add", "mix", "stir", "wait", "bake", "heat", "sift", "boil", "melt", "fry", "cool",
|
String[] verbs = {"add", "mix", "stir", "wait", "bake", "heat", "sift", "boil", "melt", "fry", "cool",
|
||||||
@@ -104,23 +46,22 @@ public class RecipeInstructions
|
|||||||
//init this shit
|
//init this shit
|
||||||
int currentNumber = 0;
|
int currentNumber = 0;
|
||||||
String currentIngredient = null;
|
String currentIngredient = null;
|
||||||
//Useless sout lol
|
//Useless sout lol <deleted dw lmao>
|
||||||
System.out.println("Enter instruction: ");
|
|
||||||
// userInput = input.nextLine();
|
// userInput = input.nextLine();
|
||||||
//this was simulating user input for the tests below
|
//this was simulating user input for the tests below
|
||||||
userInput = "mix 3 eggs and 2 milk";
|
// userInput = "mix 3 eggs and 2 milk"; <-- Commented remove for testing
|
||||||
//this is where it gets juicy
|
//this is where it gets juicy
|
||||||
//FIRST WE FIND A VERB FOR THE ACTION
|
//FIRST WE FIND A VERB FOR THE ACTION
|
||||||
for (String verb : verbs)
|
for (String verb : verbs)
|
||||||
{
|
{
|
||||||
//we regex the input for the thing
|
//we regex the input for the thing
|
||||||
if (patternMatch(verb, userInput))
|
if (patternMatch(verb, instructionIn))
|
||||||
{
|
{
|
||||||
//get Action
|
//get Action
|
||||||
RecipeNode newAction = new RecipeNode(verb, 0);
|
RecipeNode newAction = new RecipeNode(verb, 0);
|
||||||
//Split after verb
|
//Split after verb
|
||||||
//this is where we split the string
|
//this is where we split the string
|
||||||
String[] split = userInput.split(verb);
|
String[] split = instructionIn.split(verb);
|
||||||
//We get the words only POG
|
//We get the words only POG
|
||||||
String[] words = split[1].split(" ");
|
String[] words = split[1].split(" ");
|
||||||
construct_children(newAction, words);
|
construct_children(newAction, words);
|
||||||
|
|||||||
Reference in New Issue
Block a user