Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do I add: a. print out a recipe with amounts adjusted for a different number of servings b. create an additional list or ArrayList

How do I add:

a. print out a recipe with amounts adjusted for a different number of servings

b. create an additional list or ArrayList that allow users to insert step-by-step recipe instructions

c. conversion of ingredient amounts from English to metric (or vice versa)

d. calculate select nutritional information

e. calculate recipe cost

To the following code:

package SteppingStone_5

import java.util.ArrayList;

import java.util.Scanner;

public class SteppingStone5_Recipe {

private String recipeName;

private int servings;

private ArrayList recipeIngredients;

private double totalRecipeCalories = 0;

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 ArrayList getRecipeIngredients() {

return recipeIngredients;

}

public void setRecipeIngredients(ArrayList recipeIngredients) {

this.recipeIngredients = recipeIngredients;

}

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.servings = 0;

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:");

recipeIngredients.stream().forEach((ingredient) -> {

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();

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database 11g SQL

Authors: Jason Price

1st Edition

0071498508, 978-0071498500

More Books

Students also viewed these Databases questions