/*
* 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 homework;
import java.util.Scanner;
/**
*
* @author onur
*/
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
*/
String nameOfIngredient;
float numberCups;
int numberCaloriesPerCup;
double totalCalories;
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 number 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
*/
totalCalories = numberCaloriesPerCup + numberCups;
System.out.println(nameOfIngredient + " uses " +
numberCups + " cups and has " + totalCalories + " calories.");
}
}
UML Overview to pseudo-code
There are three classes in this program
This class contains the making of an ingredient and calculation
of calories in the ingredient
Class Ingredient {
Contains
A string Variable for name of ingredient
A float variable for number of cups
An integer variable for number of calories per cup
A double variable for total calories
Function getNameOfIngredient()
{
This function gets the name of ingredient
Return name of ingredient
End
}
Function setNameOfIngredient(Argument NOI)
{
This function set the value of ingredient by taking the
input from user
End
}
Function getnumberofcups()
{
This function gets the number of cups
Return number of cups
End
}
Function setNumberOfCups(Argument NOC)
{
This function takes the input from the user and set it to
variable number of cups
End
}
Function NumberOfCaloriesPerCup()
{
This function gets the Number of Calories per Cup
Return Total Calories
End
}
Function NumberOfCaloriesPerCup(Argument NOI)
{
This function set the value of Number Of Calories Per Cup
by taking the input from user
End
}
Function TotalCalories()
{
This function gets the Total Calories
Return Total Calories
End
}
Function TotalCalories(Argument NOI)
{
This function set the value of Total Calories by taking the
input from user
End
}
Function AddIngredeint()
{
This function gets value for all the member variables and set
them up to each of the member variable
End
}
End of Class
}
This class contains the information about recipe and how the
recipe would be prepared
Class Recipe {
Contains
A string Variable for Recipe Name
A Integer variable for Servings
An Array List variable for Recipe Ingredients
A double variable for Total Recipe Calories
Function getRecipeName()
{
This function gets the Recipe Name
Return Recipe Name
End
}
Function setRecipeName (Argument RN)
{
This function set the value of Recipe Name by taking the
input from user
End
}
Function getServings()
{
This function gets the number Servings
Return number of Servings
End
}
Function setServings (Argument Servings)
{
This function takes the input from the user and set it to
variable number of Servings
End
}
Function getRecipeIngredients()
{
For loop runs until Arraylist
This function gets the Recipe Ingredients list
Return Recipe Ingredients
End
}
Function setRecipeIngredients (Argument RI)
{
For loop until Array List
This function set the value of Recipe Ingredients by taking
the input from user
End
}
Function getTotalRecipeCalories()
{
This function gets the Total Recipe Calories
Return Total Recipe Calories
End
}
Function setTotalRecipeCalories (Argument TRC)
{
This function set the value of Total Recipe Calories by
taking the input from user
End
}
Function PrintRecipe()
{
This function prints value for all the member variables
End
}
Function addNewRecipe()
{
This function sets all the member variables for the new
class recipe
Return Recipe object
End
}
End of Class
}
This third Class contains the information for all recipes and
details for the recipes
Class RecipeBox
{
Member variables List Of Recipe with Array List
Function getListOfRecipes()
{
For loop until ArrayList
This function gets the List of Recipes
Return List of Recipe
End
}
Function setListOfRecipe(Argument LOR)
{
For loop until Array List
This function set the value of List of Recipe by taking
the input from user
End
}
Function RecipeBox()
{
This function gets the number of recipes in the class used
by the restaurant.
End
}
Function RecipeBox(Argument Recipe)
{
This function sets the number of recipes in the class used
by the restaurant.
End
}
Function PrintRecipeNames()
{
This function prints value for all the names of all the recipes
End
}
Function PrintallRecipedetails(Argument Recipes)
{
This function prints value for all the Details for Recipes
End
}
Function addNewRecipe()
{
This function sets all the member variables for the new
class recipe
Return Recipe object
End
}
End of Class
}
Prompt; you will write a short application that uses conditionals
to create a “forked” branching structure for the recipe manager.
Specifically, you will create a branching structure that leads to
the following output:
· If the number entered is between 1 and 100 (inclusive), the
application will display a message that says, “Good job! The
number you entered is___.”
· However, if the number entered is not between 1 and 100
(inclusive), an error message will be displayed to inform the
user that the entry does not fit the expected range: “The number
entered was not between 1 and 100!”
Guidelines for Submission: This assignment should be
submitted as a Java file.
· Adapt your Ingredient Java file to include data-type validation
steps for each of the variables in the class:
· ingredientName (String)
· ingredientAmount (float)
· unitMeasurement (String)
· Number of calories (double)

To change this license header, choose License Headers in Pr.docx

  • 1.
    /* * To changethis license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package homework; import java.util.Scanner; /** * * @author onur */ 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 */ String nameOfIngredient; float numberCups; int numberCaloriesPerCup;
  • 2.
    double totalCalories; 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 number 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 */ totalCalories = numberCaloriesPerCup + numberCups; System.out.println(nameOfIngredient + " uses " + numberCups + " cups and has " + totalCalories + " calories."); } } UML Overview to pseudo-code There are three classes in this program This class contains the making of an ingredient and calculation of calories in the ingredient Class Ingredient {
  • 3.
    Contains A string Variablefor name of ingredient A float variable for number of cups An integer variable for number of calories per cup A double variable for total calories Function getNameOfIngredient() { This function gets the name of ingredient Return name of ingredient End } Function setNameOfIngredient(Argument NOI) { This function set the value of ingredient by taking the input from user End } Function getnumberofcups() { This function gets the number of cups Return number of cups End } Function setNumberOfCups(Argument NOC) { This function takes the input from the user and set it to variable number of cups End } Function NumberOfCaloriesPerCup() { This function gets the Number of Calories per Cup Return Total Calories End } Function NumberOfCaloriesPerCup(Argument NOI)
  • 4.
    { This function setthe value of Number Of Calories Per Cup by taking the input from user End } Function TotalCalories() { This function gets the Total Calories Return Total Calories End } Function TotalCalories(Argument NOI) { This function set the value of Total Calories by taking the input from user End } Function AddIngredeint() { This function gets value for all the member variables and set them up to each of the member variable End } End of Class } This class contains the information about recipe and how the recipe would be prepared Class Recipe { Contains A string Variable for Recipe Name A Integer variable for Servings An Array List variable for Recipe Ingredients A double variable for Total Recipe Calories Function getRecipeName()
  • 5.
    { This function getsthe Recipe Name Return Recipe Name End } Function setRecipeName (Argument RN) { This function set the value of Recipe Name by taking the input from user End } Function getServings() { This function gets the number Servings Return number of Servings End } Function setServings (Argument Servings) { This function takes the input from the user and set it to variable number of Servings End } Function getRecipeIngredients() { For loop runs until Arraylist This function gets the Recipe Ingredients list Return Recipe Ingredients End } Function setRecipeIngredients (Argument RI) { For loop until Array List This function set the value of Recipe Ingredients by taking the input from user End
  • 6.
    } Function getTotalRecipeCalories() { This functiongets the Total Recipe Calories Return Total Recipe Calories End } Function setTotalRecipeCalories (Argument TRC) { This function set the value of Total Recipe Calories by taking the input from user End } Function PrintRecipe() { This function prints value for all the member variables End } Function addNewRecipe() { This function sets all the member variables for the new class recipe Return Recipe object End } End of Class } This third Class contains the information for all recipes and details for the recipes Class RecipeBox { Member variables List Of Recipe with Array List
  • 7.
    Function getListOfRecipes() { For loopuntil ArrayList This function gets the List of Recipes Return List of Recipe End } Function setListOfRecipe(Argument LOR) { For loop until Array List This function set the value of List of Recipe by taking the input from user End } Function RecipeBox() { This function gets the number of recipes in the class used by the restaurant. End } Function RecipeBox(Argument Recipe) { This function sets the number of recipes in the class used by the restaurant. End } Function PrintRecipeNames() { This function prints value for all the names of all the recipes End
  • 8.
    } Function PrintallRecipedetails(Argument Recipes) { Thisfunction prints value for all the Details for Recipes End } Function addNewRecipe() { This function sets all the member variables for the new class recipe Return Recipe object End } End of Class } Prompt; you will write a short application that uses conditionals to create a “forked” branching structure for the recipe manager. Specifically, you will create a branching structure that leads to the following output: · If the number entered is between 1 and 100 (inclusive), the application will display a message that says, “Good job! The number you entered is___.” · However, if the number entered is not between 1 and 100 (inclusive), an error message will be displayed to inform the user that the entry does not fit the expected range: “The number
  • 9.
    entered was notbetween 1 and 100!” Guidelines for Submission: This assignment should be submitted as a Java file. · Adapt your Ingredient Java file to include data-type validation steps for each of the variables in the class: · ingredientName (String) · ingredientAmount (float) · unitMeasurement (String) · Number of calories (double)