Question: Need help creating adding a driver application to the program for these two milestones Milestone 1 */ public class Ingredient { private String nameOfIngredient; //The
Need help creating adding a driver application to the program for these two milestones
Milestone 1
*/ public class Ingredient {
private String nameOfIngredient; //The String name of the ingredient
private int numberCups; //The amount of te ingredient, can be fractional
private int numberCaloriesPerCup; //The amount of unit
private String unitofMeasure; //The amount of calories
public Ingredient(String nameOfIngredient, int numberCups, int numberCaloriesPerCup, String unitofMeasure) {
this.nameOfIngredient = nameOfIngredient;
this.numberCups = numberCups;
this.numberCaloriesPerCup = numberCaloriesPerCup;
this.unitofMeasure = unitofMeasure; }
public String getNameOfIngredient() {
return nameOfIngredient;
}
public int getNumberCups() {
return numberCups;
}
public int getNumberCaloriesPerCup() {
return numberCaloriesPerCup;
}
public double getTotalCalories() {
return numberCaloriesPerCup * numberCups;
}
@Override
public String toString() {
Milestone 2
import java.util.Scanner; import java.util.ArrayList;
public class SteppingStone5_Recipe {
private String recipeName;
private double totalRecipeCalories;
private ArrayList
private int servings;
public SteppingStone5_Recipe() {
this.recipeName = "";
this.servings = 0;
this.recipeIngredients = new ArrayList<>();
this.totalRecipeCalories = 0;
}
public SteppingStone5_Recipe(String recipeName, int servings, ArrayList recipeIngredients, double totalRecipeCalories) {
this.recipeName = recipeName;
this.servings = servings;
this.recipeIngredients = recipeIngredients;
this.totalRecipeCalories = totalRecipeCalories;
}
public String getRecipeName() {
return recipeName;
}
public void setRecipeName(String recipeName) {
this.recipeName = recipeName;
}
public double getTotalRecipeCalories() {
return totalRecipeCalories;
}
public void setTotalRecipeCalories(double totalRecipeCalories) {
this.totalRecipeCalories = totalRecipeCalories;
}
public ArrayList getRecipeIngredients() {
return recipeIngredients;
}
public void setRecipeIngredients(ArrayList recipeIngredients) {
this.recipeIngredients = recipeIngredients;
}
public int getServings() {
return servings;
}
public void setServings(int servings) {
this.servings = servings;
}
public void printRecipe() {
int singleServingCalories = (int) (totalRecipeCalories / servings);
System.out.println("Recipe: " + recipeName);
System.out.println("Serves: " + servings);
System.out.println("Ingredients:");
for (String ingredient : recipeIngredients) {
System.out.println(ingredient);
}
System.out.println("Each serving has " + singleServingCalories + " Calories.");
}
public static void main(String[] args) {
SteppingStone5_Recipe recipe1 = createNewRecipe(); recipe1.printRecipe();
} public static SteppingStone5_Recipe createNewRecipe() { double totalRecipeCalories = 0;
ArrayList
boolean addMoreIngredients = true;
Scanner scnr = new Scanner(System.in);
System.out.println("Please enter the recipe name: ");
String recipeName = scnr.nextLine();
System.out.println("Please enter the number of servings: ");
int servings = scnr.nextInt();
do {
System.out.println("Please enter the ingredient name" + " or type end if you are finished entering ingredients: ");
String ingredientName = scnr.next();
if (ingredientName.toLowerCase().equals("end")) {
addMoreIngredients = false;
} else {
recipeIngredients.add(ingredientName);
System.out.println("Please enter the ingredient amount: ");
float ingredientAmount = scnr.nextFloat();
System.out.println("Please enter the ingredient Calories: ");
int ingredientCalories = scnr.nextInt();
totalRecipeCalories += (ingredientCalories * ingredientAmount);
}
} while (addMoreIngredients);
SteppingStone5_Recipe recipe1 = new SteppingStone5_Recipe(recipeName, servings, recipeIngredients, totalRecipeCalories);
scnr.close(); return recipe1; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
