Question: Help!!!! i need help Your Ingredient class will model the details of individual ingredients in a recipe. Based on Stepping Stone Labs Two and Three,
Help!!!!
i need help
Your Ingredient class will model the details of individual ingredients in a recipe. Based on Stepping Stone Labs Two and Three, you will create an Ingredient class and give it the basic attributes: name, amount, unit of measure, and calories. Ensure you add these as instance variables of the ingredient class. Additionally, you will add code to validate the data type of the user input.
Here is stepping stone 2
package SteppingStones;
import java.util.Scanner; /** * * */ public class SteppingStone2_IngredientCalculator {
/** * @param args the command line arguments */ public static void main(String[] args) { /** *Assign the following variables with the appropriate data type and value: *VARIABLE NAME VALUE *nameOfIngredient "" *numberCups 0 *numberCaloriesPerCup 0 *totalCalories 0.0 */ Scanner scnr = new Scanner(System.in); System.out.println("Please enter the name of the ingredient: "); nameOfIngredient = scnr.next(); System.out.println("Please enter the number of cups of " + nameOfIngredient + " we'll need: "); numberCups = scnr.nextFloat(); System.out.println("Please enter the name of calories per cup: "); numberCaloriesPerCup = scnr.nextInt(); /** * Write an expression that multiplies the number of cups * by the Calories per cup. * Assign this value to totalCalories */ System.out.println(nameOfIngredient + " uses " + numberCups + " cups and has " + totalCalories + " calories."); total calories = NumCups + NumCalories } }
/** * * Final Project * *For your Final Project: * * 1. Create a new java class named Ingredient * * 2. Adapt the code from this SteppingStone to include the following changes: * * a. Rename the variable, numberCups, to represent the more general * ingredientAmount; * * b. Add a new text variable, unitMeasurement to store unit of measurement * for the ingredient amount (e.g. cups, oz., etc.); * * c. Prompt the user to input the measurement unit; * * /
here is stepping stone 3
public class SteppingStone4_Loops {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
String recipeName = "";
ArrayList
String newIngredient = "";
boolean addMoreIngredients = true;
System.out.println("Please enter the recipe name: ");
recipeName = scnr.nextLine();
do {
System.out.println("Would you like to enter an ingredient: (y or n)");
String reply = scnr.next().toLowerCase();
/**
* Add your code here (branches work well!). The code should check the
* reply:
* "y" --> prompt for the ingredient and add it to the ingredient list;
* "n" --> break out of the loop;
* (Hint: what is the 'while' condition? What could you change to
* stop the loop from starting over?)
* anything else --> prompt for a "y" or "n"
*
*/
while (true) {
if (reply.equals("y")) {
System.out.println("Enter ingredient name: ");
newIngredient = scnr.next();
ingredientList.add(newIngredient);
break;
}
else if (reply.equals("n")) {
System.out.println("Goodbye!");
addMoreIngredients = false;
break;
{
else
break;
}
} while (addMoreIngredients);
for (int i = 0; i < ingredientList.size(); i++) {
/**
* Get the item i from the ingredient list
* and assing it to the String ingredient
*
*/
String ingredient = ???;
System.out.println(ingredient);
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
