I would like someone to check my code and help with my for loop to print the recipe. It is incorrect.
package SteppingStones;
import java.util.Scanner; //Scanner class//
import java.util.ArrayList; //ArrayList//
import ingredients.Ingredient;
/**Gets from package ingredients and class Ingredient
*
* @author kimbe
*/
public class SteppingStone5_Recipe {
//Instance Variables//
private ArrayList recipeIngredients;
private String recipeName;
private int servings;
private double totalRecipeCalories;
//Setter and Getters//
public ArrayList getrecipeIngredients() {
return recipeIngredients;
}
public void setrecipeIngredients(ArrayListrecipeIngredients)
{
this.recipeIngredients = recipeIngredients;
}
public String getRecipeName () {
return recipeName;
}
public void setRecipeName (String recipeName) {
this.recipeName = recipeName;
}
public int getServings () {
return servings;
}
public void setServings (int servings) {
this.servings = servings;
}
public double getTotalRecipeCalories () {
return totalRecipeCalories;
}
public void setTotalRecipeCalories (double totalRecipeCalories)
{
this.totalRecipeCalories = totalRecipeCalories;
}
public SteppingStone5_Recipe() {
this.recipeName = "";
this.servings = 0; //<--- assignment value with appropriate data
type
this.recipeIngredients = new ArrayList <>(); //<--
assignment value for empty ArrayList
this.totalRecipeCalories = 0;
}
public SteppingStone5_Recipe(String recipeName, int servings,
ArrayList recipeIngredients, double
totalRecipeCalories)
//<-- use appropriate data type for the ArrayList and the
servings arguments
{
this.recipeName = recipeName;
this.servings = servings;
this.recipeIngredients = recipeIngredients;
this.totalRecipeCalories = totalRecipeCalories;
}
public void printRecipe() {
int singleServingCalories = 0;
singleServingCalories = (int) (totalRecipeCalories/servings);
System.out.println ("Recipe " + this.recipeName);
System.out.println ("Serves " + this.servings);
System.out.println ("Ingredients: ");
for (Ingredient i : recipeIngredients) {
}
/**
* Declare an int variable singleServingCalories.
* Assign singleServingCalories to
* the totalRecipeCalories divided by the servings
*
*/
/**
* Print the following recipe information:
* Recipe: <>
* Serves: <>
* Ingredients:
* <>
* <>
* ...
* <>
*
* Each serving has <> Calories.
*
* HINT --> Use a for loop to iterate through the ingredients
*/
/**
* Print the following recipe information:
Recipe: <>
Serves: <>
Ingredients:
<>
<>
...<>
Each serving has <> Calories.
HINT --> Use a for loop to iterate through the
ingredients
* @param args
*/
}
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: ");
//correct data type & Scanner assignment method for servings
variable
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 {
Ingredient anIngredient = new Ingredient();
anIngredient.setNameOfIngredient(ingredientName);
addMoreIngredients = true;
/**
* Add the ingredient name to recipeIngredients
*
*/
System.out.println("Please enter the ingredient amount: ");
float ingredientAmount = scnr.nextFloat();
anIngredient.setIngredientAmount(ingredientAmount);
System.out.println("Please enter the ingredient Calories: ");
int ingredientCalories = scnr.nextInt();
anIngredient.setNumberCaloriesPerUnit(ingredientCalories);
totalRecipeCalories = (ingredientCalories *
ingredientAmount);
anIngredient.setTotalCalories(totalRecipeCalories);
recipeIngredients.add(anIngredient);
/**
* Add the total Calories from this ingredient
* (ingredientCalories * ingredientAmount)
* to the totalRecipeCalories
*
*/
}
} while (addMoreIngredients == true) ;
SteppingStone5_Recipe recipe1 = new
SteppingStone5_Recipe(recipeName,
servings, recipeIngredients, totalRecipeCalories);
recipe1.printRecipe();
}
}
/*
* 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 ingredients;
import java.util.ArrayList;
/**
*
* @author kimbe
*/
public class Ingredient {
private String nameOfIngredient; /** String is used because it
is
* characters
* @return
*/
public Ingredient( String NameOfIngredient, double
ingredientAmount, String
unitMeasurement, double totalCalories, int
numberCaloriesPerUnit){
this.nameOfIngredient = nameOfIngredient;
this.ingredientAmount = (float) ingredientAmount;
this.numberCaloriesPerUnit = numberCaloriesPerUnit;
this.unitMeasurement = unitMeasurement;
this.totalCalories = totalCalories;
}
public Ingredient() {
}
//Getter//
public String getNameOfIngredient () {
return nameOfIngredient;
}
//Setter//
public void setNameOfIngredient (String newName) {
this.nameOfIngredient = newName;
}
/*This getter and setter allows public access to the private
variable
nameOfIngredient
*/
private String unitMeasurement; /** String is used because it is
characters
*
* @return
*/
//Getter//
public String getUnitMeasurement () {
return unitMeasurement;
}
//Setter//
public void setUnitMeasurement (String newName) {
this.unitMeasurement = newName;
/**This getter and setter allows public access to the private
variable
* unitMeasurement
*
*/
}
private float ingredientAmount; /** Will be a float because it is a
decimal
* Cups could be 2.5 cups for example
* @return
*/
//Getter//
public float getIngredientAmount () {
return ingredientAmount;
}
//Setter//
public void setIngredientAmount (float newName) {
this.ingredientAmount = newName;
}
/**This getter and setter allows public access to the private
variable
* ingredientAmount
*/
private int numberCaloriesPerUnit; /** Calories are whole numbers
so
* this will be an integer
* @return
*/
//Getter//
public int getNumberCaloriesPerUnit () {
return numberCaloriesPerUnit;
}
//Setter//
public void setNumberCaloriesPerUnit (int newName) {
this.numberCaloriesPerUnit = newName;
/**This getter and setter allows public access to the private
* variable numberCaloriesPerUnit
*/
}
private double totalCalories; /** using double to be more precise.
It
* will be a decimal number
*
* @return
*/
//Getter//
public double getTotalCalories () {
return totalCalories;
}
public void setTotalCalories (double newName) {
this.totalCalories = newName;
/**This getter and setter allows public access to the private
* variable totalCalories
*
*/
}
public StringtoString(){
return "Ingredient =" + nameOfIngredient" + "ingredientAmount
+ numberCaloriesPerUnit" + unitMeasurement" +
totalCalories"
}
}
/***********************************SteppingStone5_Recipe.java***********************/
package SteppingStones;
import java.util.Scanner; //Scanner class//
import java.util.ArrayList; //ArrayList//
/**
* Gets from package ingredients and class Ingredient
*
* @author kimbe
*/
public class SteppingStone5_Recipe {
//Instance Variables//
private ArrayList<Ingredient>
recipeIngredients;
private String recipeName;
private int servings;
private double totalRecipeCalories;
//Setter and Getters//
public ArrayList<Ingredient>
getrecipeIngredients() {
return recipeIngredients;
}
public void
setrecipeIngredients(ArrayList<Ingredient> recipeIngredients)
{
this.recipeIngredients =
recipeIngredients;
}
public String getRecipeName() {
return recipeName;
}
public void setRecipeName(String recipeName)
{
this.recipeName = recipeName;
}
public int getServings() {
return servings;
}
public void setServings(int servings) {
this.servings = servings;
}
public double getTotalRecipeCalories() {
return totalRecipeCalories;
}
public void setTotalRecipeCalories(double
totalRecipeCalories) {
this.totalRecipeCalories =
totalRecipeCalories;
}
public SteppingStone5_Recipe() {
this.recipeName = "";
this.servings = 0; // <---
assignment value with appropriate data type
this.recipeIngredients = new
ArrayList<>(); // <-- assignment value for empty
ArrayList
this.totalRecipeCalories = 0;
}
public SteppingStone5_Recipe(String recipeName, int
servings, ArrayList<Ingredient> recipeIngredients,
double
totalRecipeCalories)
//<-- use appropriate data type for the ArrayList and the
servings arguments
{
this.recipeName = recipeName;
this.servings = servings;
this.recipeIngredients =
recipeIngredients;
this.totalRecipeCalories =
totalRecipeCalories;
}
public void printRecipe() {
int singleServingCalories = (int) (totalRecipeCalories / servings);
System.out.println("Recipe: " + recipeName);
System.out.println("Serves: " + servings);
System.out.println("Ingredients:");
for (Ingredient ingredient : recipeIngredients) {
System.out.println(ingredient.toString());
}
System.out.println("Each serving has " + singleServingCalories + " Calories.");
}
public static void main(String[] args) {
double totalRecipeCalories =
0;
ArrayList<Ingredient>
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: ");
//correct data type & Scanner assignment method for servings
variable
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 {
Ingredient anIngredient = new
Ingredient();
anIngredient.setNameOfIngredient(ingredientName);
addMoreIngredients = true;
/**
* Add the ingredient name to
recipeIngredients
*
*/
System.out.println("Please enter the ingredient
amount: ");
float ingredientAmount = scnr.nextFloat();
anIngredient.setIngredientAmount(ingredientAmount);
System.out.println("Please enter the ingredient
Calories: ");
int ingredientCalories = scnr.nextInt();
anIngredient.setNumberCaloriesPerUnit(ingredientCalories);
anIngredient.setIngredientAmount(ingredientAmount);
totalRecipeCalories = (ingredientCalories *
ingredientAmount);
anIngredient.setTotalCalories(totalRecipeCalories);
recipeIngredients.add(anIngredient);
/**
* Add the total Calories from this ingredient
(ingredientCalories *
* ingredientAmount) to the
totalRecipeCalories
*
*/
}
} while (addMoreIngredients == true);
SteppingStone5_Recipe recipe1 =
new SteppingStone5_Recipe(recipeName, servings,
recipeIngredients,
totalRecipeCalories);
recipe1.printRecipe();
}
}
/*
* 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.
*/
/*************output***************/
Please enter the recipe name:
pizza
Please enter the number of servings:
2
Please enter the ingredient name or type end if you are finished
entering ingredients:
Crust
Please enter the ingredient amount:
10
Please enter the ingredient Calories:
100
Please enter the ingredient name or type end if you are finished
entering ingredients:
sauce
Please enter the ingredient amount:
20
Please enter the ingredient Calories:
100
Please enter the ingredient name or type end if you are finished
entering ingredients:
Cheese
Please enter the ingredient amount:
20
Please enter the ingredient Calories:
200
Please enter the ingredient name or type end if you are finished
entering ingredients:
end
Recipe: pizza
Serves: 2
Ingredients:
Ingredient =Crust 10.0 100 null 1000.0
Ingredient =sauce 20.0 100 null 2000.0
Ingredient =Cheese 20.0 200 null 4000.0
Each serving has 2000 Calories.
Please let me know if you have any doubt or modify the answer, Thanks :)
I would like someone to check my code and help with my for loop to print...
Can someone help me with my code.. I cant get an output. It says I do not have a main method. HELP PLEASE. The instruction are in bold on the bottom of the code. package SteppingStones; //Denisse.Carbo import java.util.Scanner; import java.util.ArrayList; import java.util.List; public class SteppingStone5_Recipe { private String recipeName; private int servings; private List<String> recipeIngredients; private double totalRecipeCalories; public String getRecipeName() { return recipeName; } public void setRecipeName (string recipeName){ this.recipeName = recipeName; } public int getServings() { return...
I'm getting a few errors still under RecipeBox. Would you be able to see what's wrong? Thanks ------------ package recipecollection; import java.util.ArrayList; public class SteppingStone5_RecipeTest { public static void main(String[] args) { ArrayList<String> recipeIngredients = new ArrayList<>(); recipeIngredients.add("Peanut butter"); recipeIngredients.add("Jelly"); recipeIngredients.add("Bread"); SteppingStone5_Recipe recipe1 = new SteppingStone5_Recipe("Peanut butter & jelly sandwich", 2, recipeIngredients, 300, 10.0); System.out.println("RECIPE 1"); recipe1.printRecipe(); System.out.println(); recipe1.setRecipeName("Turkey sandwich"); recipe1.setServings(5); recipe1.setTotalRecipeCalories(500); System.out.println(); System.out.println("RECIPE 1 (Modified)"); recipe1.printRecipe(); System.out.println(); System.out.println("RECIPE 2"); SteppingStone5_Recipe recipe2 = SteppingStone5_Recipe.createNewRecipe(); recipe2.printRecipe(); } } ///////////////// package recipecollection;...
How to build Java test class? I am supposed to create both a recipe class, and then a class tester to test the recipe class. Below is what I have for the recipe class, but I have no idea what/or how I am supposed to go about creating the test class. Am I supposed to somehow call the recipe class within the test class? if so, how? Thanks in advance! This is my recipe class: package steppingstone5_recipe; /** * *...
Prompt: In this stepping stone lab assignment, you will build a Recipe class, getting user input to collect the recipe name and serving size, using the ingredient entry code from Stepping Stone Lab Four to add ingredients to the recipe, and calculating the calories per serving. Additionally, you will build your first custom method to print the recipe to the screen. Specifically, you will need to create the following: The instance variables for the class (recipeName, serving size, and...
Hi. Could you help me with the code below? I need to validate the code below, using expressions that can carry out the actions or that make appropriate changes to the program’s state, using conditional and iterative control structures that repeat actions as needed. The unit measurement is missing from the final output and I need it to offer options to lbs, oz, grams, tbsp, tsp, qt, pt, and gal. & fl. oz. Can this be added? The final output...
I cannot submit my entire project due to the word count limit. I think my project looks ok, but my recipe box class and recipe test class is running errors and it may have something to do with the menu portion of the recipe box. Please take a look: "You will create a program that will help you manage a collection of recipes. You will implement three classes: one for the main recipe items, one for the ingredients that are...
*Please Add Inline Comments Directed toward software engineers about design decisions to facilitate the programs ongoing maintenance* import java.util.ArrayList; import java.util.Scanner; /** * * @author Eli Mishkit */ public class SteppingStone6_RecipeBox { /** * Declare instance variables: * a private ArrayList of the type SteppingStone5_Recipe named listOfRecipes * */ private ArrayList<SteppingStone5_Recipe> listOfRecipes; /** * Add accessor and mutator for listOfRecipes * */ public ArrayList<SteppingStone5_Recipe> getListOfRecipes() { return listOfRecipes; } public void setListOfRecipes(ArrayList<SteppingStone5_Recipe> listOfRecipes) { this.listOfRecipes = listOfRecipes; } /** *...
Below are the Car class and Dealership class that I
created In the previous lab
import java.util.ArrayList;
class Car
{
private String make;
private String model;
private int year;
private double transmission;
private int seats;
private int maxSpeed;
private int wheels;
private String type;
public Car()
{
}
public Car(String make, String model, int year, double transmission, int seats, int maxSpeed, int wheels, String type) {
this.make = make;
this.model = model;
this.year = year;
this.transmission = transmission;
this.seats =...
please rewrite this code as Pseudo-Code,.. basically rewrite the code but in english language , Thank you so much! public abstract class BankAccount { //declare the required class variables private double balance; private int num_deposits; private int num_withdraws; private double annualInterest; private double serviceCharges; //constructor that takes two arguments // one is to initialize the balance and other // to initialize the annual interest rate public BankAccount(double balance,...
I need help with adding comments to my code and I need a uml diagram for it. PLs help.... Zipcodeproject.java package zipcodesproject; import java.util.Scanner; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class Zipcodesproject { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner input=new Scanner(System.in); BufferedReader reader; int code; String state,town; ziplist listOFCodes=new ziplist(); try { reader = new BufferedReader(new FileReader("C:UsersJayDesktopzipcodes.txt")); String line = reader.readLine(); while (line != null) { code=Integer.parseInt(line); line =...