Switch to add ingredients and compile the full recipe.

This commit is contained in:
2022-06-02 15:19:24 +02:00
parent d0ec5c8c74
commit 0959c45e61
3 changed files with 99 additions and 1 deletions

2
.idea/misc.xml generated
View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_13" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@@ -23,5 +23,31 @@
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="JUnit4">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.13.1/junit-4.13.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="JUnit5.8.1">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.8.1/junit-jupiter-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.8.1/junit-jupiter-api-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.8.1/junit-platform-commons-1.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.8.1/junit-jupiter-params-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.8.1/junit-jupiter-engine-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.8.1/junit-platform-engine-1.8.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>

View File

@@ -0,0 +1,72 @@
import java.awt.image.AreaAveragingScaleFilter;
import java.util.ArrayList;
import java.util.Scanner;
public class RecipeInstructions {
public static void main(String[] args) {
int usrChoice;
ArrayList<RecipeNode> ingredients = new ArrayList<>();
RecipeTree fullInstructions = new RecipeTree();
do {
Scanner userOption = new Scanner(System.in);
System.out.println("What would you like to do?\n1.Add Ingredient\n2.Mix");
usrChoice = userOption.nextInt();
// Switch case for user's choice
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);
}
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);
}
}