02 Jun As you are learning, data types can move from the simple to complex as we construct programs designed to solve problems. The second stepping stone lab presents an opportunity for
As you are learning, data types can move from the simple to complex as we construct programs designed to solve problems. The second stepping stone lab presents an opportunity for you to create primitive data types then use them to construct the more complex forms of strings and arrays as you begin to develop code for a recipe manager program.
Starting with Stepping Stone Lab Two and continuing to the last stepping stone lab in Module Six, you will develop code for the program described in the Stepping Stone Overview PDF document. You will start with a simple structure and gradually build in additional complexity and functionality. The overview also illustrates steps for completing and submitting these labs.
The stepping stone labs constitute a foundation upon which you will build the program you will submit for your final project. Most of the stepping stone labs outline the additional requirements for revising and expanding the concepts in the stepping stone labs as you work on the final project.
Stepping Stone Lab Two, provide the code for those 2 prompts (highlighted in green on the guidelines document) and a written explanation of it
Stepping Stone Lab Two Guidelines Recipe Manager Data Types
Overview: For this stepping stone lab and others to come, you will create coding for a program designed to manage recipes.
In Stepping Stone Lab Two, you will begin working with a recipe manager program by focusing on a single ingredient. You will be introduced to basic data types to store numeric values and string values.
You will build this ingredient in code that reflects variables such as its name, the number of cups of that ingredient needed in the recipe, and how many calories it has per cup. You will also write an expression to calculate the total number of calories this ingredient would contribute to a recipe.
To keep track of this information, you need to store it in a program. You will need to utilize variables of various data types to store the information and prompt the user for the various values. Once you get that information from the user, you can calculate the total number of calories per serving in your recipe.
Prompt: Use SteppingStone2_IngredientCalculator.java as your base code. Areas that require changes to the base code and/or additional code to be written are found in the commented areas that look like this:
/**
· This is a commented area that describes the task to be completed in this stepping stone *
*/
Specifically, you will complete the following:
A. Assign the variables with the appropriate data type and value as shown in the table below:
Variable Name |
Type of Value Stored |
nameOfIngredient |
Text |
numberOfCups |
Decimal numbers (e.g., ½ a cup) |
numberOfCaloriesPerCup |
Whole numbers |
totalCalories |
Decimal numbers |
B. Write an expression that multiplies the numberOfCups by the numberOfCalories per cup and assign this value to totalCalories.
Guidelines for Submission: This assignment should be submitted as a Java file.
Extending This Lab for Your Final Project
For your final project, do the following:
1. Create a new java class named Ingredient.
2. Adapt the code from this stepping stone 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 (cups, ounces, etc.). C. Prompt the user to input the measurement unit.
SteppingStone2_IngredientCalculator.java
package SteppingStones;
import java.util.Scanner;
/**
*
· @author j.leone1
*/
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 NAMEVALUE
*nameOfIngredient ""
*numberCups0
*numberCaloriesPerCup 0
*totalCalories0.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.");
}
}
,
/* * 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; 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.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."); } } /** * * 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; * * /