Question: Ive almost finished the Recipe.java file and a Recipe_Test.java file (all below), but need help with the following items: Instance variables: recipeName, servings, recipeIngredients, and
Ive almost finished the Recipe.java file and a Recipe_Test.java file (all below), but need help with the following items:
Instance variables: recipeName, servings, recipeIngredients, and totalRecipeCalories
Accessors and mutators for the instance variables
Constructors
A printRecipe() method
A createNewRecipe() method to build a recipe from user input
Pseudocode for the custom method selected from the list in Stepping Stone Lab Five
The Recipe_Test.java file containing a main() method that:
Uses a constructor to create a new recipe
Accesses the printRecipe() method to print the formatted recipe
Invokes the createNewRecipe() method to accept user input
Specifically, the following critical elements of the final project are addressed:
I. Data Types: Your Recipe class should properly employ each of the following data types that meet the scenarios requirements where necessary:
A. Utilize appropriate numerical and string data types to represent values for variables and attributes in your program.
B. Populate a list or array that allows the management of a set of values as a single unit in your program.
II. Algorithms and Control Structure: Your Recipe class should properly employ each of the following control structures as required or defined by the
scenario where necessary:
A. Utilize expressions or statements that carry out appropriate actions or that make appropriate changes to your programs state as represented in
your programs variables.
B. Employ the appropriate conditional control structures that enable choosing between options in your program.
C. Utilize iterative control structures that repeat actions as needed to achieve the programs goal.
III. Methods: Your Recipe class should properly employ each of the following aspects of method definition as determined by the scenarios requirements
where necessary:
A. Use formal parameters that provide local variables in a functions definition.
B. Use actual parameters that send data as arguments in function calls.
C. Create both value-returning and void functions to be parts of expressions or stand-alone statements in your program.
D. Invoke methods that access the services provided by an object.
E. Describe a user-defined method that provides custom services for an object.
F. Create unit tests that ensure validity of the methods.
IV. Classes: Construct classes for your program that include the following as required by the scenario where necessary:
A. Include attributes that allow for encapsulation and information hiding in your program.
B. Include appropriate methods that provide an objects behaviors.
V. Documentation: Utilize inline comments directed toward software engineers for the ongoing maintenance of your program that explain the decisions
you made in the construction of the classes in your program.
SteppingStone5_Recipe.java:
import java.util.Scanner;
import java.util.ArrayList;
/**
*
* @author
*/
public class SteppingStone5_Recipe {
private String recipeName;
private double totalRecipeCalories;
private ArrayList recipeIngredients;
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) {
double totalRecipeCalories = 0;
ArrayList recipeIngredients = new 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);
recipe1.printRecipe();
scnr.close();
}
}
And here is the test file
//SteppingStone5_recipeTester.java
import java.util.ArrayList;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package SteppingStones;
/**
*
* @author
*/
public class SteppingStone5_RecipeTest {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// Create two recipe objects first
SteppingStone5_Recipe myFirstRecipe = new SteppingStone5_Recipe();
ArrayList recipeIngredients = new ArrayList();
ArrayList recipeIngredientsTwo = new ArrayList();
String ingredientName = "Anchovies";
Ingredient tempIngredient = new Ingredient().addNewIngredient(ingredientName);
recipeIngredients.add(tempIngredient);
SteppingStone5_Recipe mySecondRecipe = new SteppingStone5_Recipe("Pizza", 2, recipeIngredients, 300);
// Initialize first recipe
String ingredientNameTwo = "Noodles";
Ingredient tempIngredientTwo = new Ingredient().addNewIngredient(ingredientNameTwo);
recipeIngredientsTwo.add(tempIngredientTwo);
myFirstRecipe.setRecipeName("Ramen");
myFirstRecipe.setServings(2);
myFirstRecipe.setRecipeIngredients(recipeIngredientsTwo);
myFirstRecipe.setTotalRecipeCalories(150);
// Print details of both recipes
myFirstRecipe.printRecipe();
mySecondRecipe.printRecipe();
}
}
Step by Step Solution
There are 3 Steps involved in it
To provide a more detailed and thoroughly structured response lets revise the initial response by breaking down each step required to build the Recipe and RecipeTest components specified in your quest... View full answer
Get step-by-step solutions from verified subject matter experts
