Question
Overview: In your final project, you will create a program that will help you manage a collection of items. To complete this program, you will
Overview: In your final project, you will create a program that will help you manage a collection of items. To complete this program, you will implement two classes: one for the main item and one for the entire collection. If you decide to be more adventurous, you can make an additional class for the most important subcomponent of your main item class. Prompt: Your Ingredient class will model the details of individual ingredients in a recipe. Based on Stepping Stone Labs Two and Three, you will create an Ingredient class and give it the basic attributes: name, amount, unit of measure, and calories. Ensure you add these as instance variables of the ingredient class. Additionally, you will add code to validate the data type of the user input. This Ingredient class will be modified for the submission of your final RecipeManager application; however, it should be functional code that accepts user input for each variable. Specifically, the following critical elements of the final project must be addressed: I. Data Types: Your Ingredient class should properly employ each of the following data types that meet the scenarios requirements where necessary: A. Utilize numerical data types that represent quantitative values for variables and attributes in your class. B. Utilize strings that represent a sequence of characters needed as a value in your class. C. Utilize inline comments directed toward software engineers for the ongoing maintenance of your program that explain your choices of data types selected for your program. II. Algorithms and Control Structure: Your final program 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 inline comments directed toward software engineers for the ongoing maintenance of your program that explain your choices of data types selected for your program. Guidelines for Submission: Your complete program should be submitted as a Java file of the project.
Stepping Stone Lab 2 import java.util.Scanner;
/* * 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. */
/** * * @author emishkit */ public class SteppingStone2_IngredientsCalculator {
/** * @param args the command line arguments */ public static void main(String[] args) { String nameOfIngredient = ""; int numberCups = 0; int numberCaloriesPerCup = 0; double totalCalories = 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.nextInt();
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.");
scnr.close(); } } Stepping Stone Lab 3 /* * 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 SteppingStone3_Branches {
public static void main(String[] args) { int numberCups = -1; /** * Add a CONSTANT variable MAX_CUPS assigned to the value 100 */ final int MAX_CUPS=100,MIN_CUPS=1;
Scanner scnr = new Scanner(System.in);
System.out.println("Please enter the number of cups (between 1 and 100): ");
//The following "if branch" uses the scanner method hasNextInt() to //check to see if the input is an int. if (scnr.hasNextInt()) { numberCups = scnr.nextInt();
if(numberCups>MIN_CUPS && numberCups<=MAX_CUPS)
System.out.println("Good job! The number you entered is: "+numberCups);
else { System.out.println( "The number entered was not between 1 and 100!"); System.out.println("Please enter another number of cups between 1 and 100: "); numberCups = scnr.nextInt(); if(numberCups>MIN_CUPS && numberCups<=MAX_CUPS) System.out.println("Good job! The number you entered is: "+numberCups); else if(numberCups } else { System.out.println("Error: That is not a number. Try again."); } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started