Question

Can someone help me with my code.. I cant get an output. It says I do...

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 servings;
}
public void setServings(int servings) {
this.servings = servings;
}
public List<String> getRecipeIngredients() {
return recipeIngredients;
}
public void setRecipeIngredients() {
this.recipeIngredients = recipeIngredients;
}
public double getTotalRecipeCalories() {
return totalRecipeCalories;
}
public void setTotalRecipeCalories(double totalRecipeCalories) {
this.totalRecipeCalories = totalRecipeCalories;
}

public SteppingStone5_Recipe() {
this.recipeName = "";
this.servings = 0;
this.recipeIngredients = new ArrayList<String> ();
this.totalRecipeCalories = 0;

}
public SteppingStone5_Recipe(String recipeName, int servings,
ArrayList<String> recipeIngredients, double totalRecipeCalories)

{
this.recipeName = recipeName;
this.servings = servings;
this.recipeIngredients = recipeIngredients;
this.totalRecipeCalories = totalRecipeCalories;
}

public void printRecipe() {
int singleServingCalories = 0;
singleServingCalories = (int) (this.totalRecipeCalories/this.servings);

System.out.println("Recipes: " + this.recipeName);
System.out.println("Serves: " + this.servings);
System.out.println("Ingredients: ");
for(String ingredients: recipeIngredients){
System.out.println(ingredients);
System.out.println("Each sercing has: " + singleServingCalories + "Calories.");
}
}


public static void main(string[]args ) {
double totalRecipeCalories = 0.0;
ArrayList <String> 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 = 0;


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 {

/**
* Add the ingredient name to recipeIngredients
*
*/

System.out.println("Please enter the ingredient amount: ");
float ingredientAmount = scnr.nextFloat();

System.out.println("Please enter the ingredient Calories: ");
int ingredientCalories = scnr.nextInt();

/**
* Add the total Calories from this ingredient
* (ingredientCalories * ingredientAmount)
* to the totalRecipeCalories
*
*/

}

} while (!reply.equals("n") ;

SteppingStone5_Recipe recipe1 = new SteppingStone5_Recipe(recipeName,
servings, recipeIngredients, totalRecipeCalories);
recipe1.printRecipe();
}

private static class string {

public string() {
}
}
}


/**

* 1. Modify this code to develop a Recipe class:
* a. change the void main method createNewRecipe() that returns a Recipe
*
* 2. FOR FINAL SUBMISSION ONLY:Change the ArrayList type to an
* Ingredient object. When a user adds an ingredient to the recipe,
* instead of adding just the ingredient name, you will be adding the
* actual ingredient including name, amount, measurement type, calories.
* For the Milestone Two submission, the recipeIngredients ArrayList can
* remain as a String type.
*
* 3. Adapt the printRecipe() method to print the amount and measurement
* type as well as the ingredient name.
*
* 4. Create a custom method in the Recipe class.
* Choose one of the following options:
*
* 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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I have updated the given code to work correctly with respect to the comments given in the code.

Please find the code screenshot, output, and Code

ANY CLARIFICATIONS REQUIRED LEAVE A COMMENT

1.CODE SCREENSHOT.

ir A WN Stepping Stone5_Recipe.java X 1 import java.util.Scanner; import java.util.ArrayList; import java.util.List; public c

Stepping Stone5_Recipe.java X 28 Spublic double getTotalRecipecalories () { 29 return totalRecipeCalories; 30 } 31 public voi

} Stepping Stone5_Recipe.java X 55 56 System.out.println(Recipes: + this.recipeName); 57 System.out.println(Serves: + thi

* Stepping Stone5_Recipe java X 81 Edo { 82 System.out.println(Please enter the ingredient name or type end if you are finis

105 106 totalRecipecalories+=(ingredientcalories * ingredientAmount); 107 } 108 -} while (addMore Ingredients); 109 110 Estep

2.OUTPUT

CX C:\WINDOWS\system32\cmd.exe D:\javasrc>javac SteppingStone5_Recipe.java Note: SteppingStone5_Recipe.java uses unchecked or

3.CODE:

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 servings;
}
public void setServings(int servings) {
this.servings = servings;
}
public List<String> getRecipeIngredients() {
return recipeIngredients;
}
public void setRecipeIngredients() {
this.recipeIngredients = recipeIngredients;
}
public double getTotalRecipeCalories() {
return totalRecipeCalories;
}
public void setTotalRecipeCalories(double totalRecipeCalories) {
this.totalRecipeCalories = totalRecipeCalories;
}

public SteppingStone5_Recipe() {
this.recipeName = "";
this.servings = 0;
this.recipeIngredients = new ArrayList<String> ();
this.totalRecipeCalories = 0;

}
public SteppingStone5_Recipe(String recipeName, int servings,
ArrayList<String> recipeIngredients, double totalRecipeCalories)

{
this.recipeName = recipeName;
this.servings = servings;
this.recipeIngredients = recipeIngredients;
this.totalRecipeCalories = totalRecipeCalories;
}

public void printRecipe() {
int singleServingCalories = 0;
singleServingCalories = (int) (this.totalRecipeCalories/this.servings);

System.out.println("Recipes: " + this.recipeName);
System.out.println("Serves: " + this.servings);
System.out.println("Ingredients: ");
for(String ingredients: recipeIngredients){
System.out.println(ingredients);

}
System.out.println("Each serving has: " + singleServingCalories + "Calories.");
}


public static void main(String[] args ) {
double totalRecipeCalories = 0.0;
ArrayList <String> recipeIngredients = new ArrayList();
boolean addMoreIngredients = true;

Scanner scnr = new Scanner(System.in);

System.out.println("Please enter the recipe name: ");
String recipeName = scnr.next();

System.out.println("Please enter the number of servings: ");
//correct data type & Scanner assignment method for servings variable
int servings = 0;
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 {

/**
* Add the ingredient name to recipeIngredients
*
*/
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();

/**
* Add the total Calories from this ingredient
* (ingredientCalories * ingredientAmount)
* to the totalRecipeCalories
*
*/

totalRecipeCalories+=(ingredientCalories * ingredientAmount);
}
} while (addMoreIngredients) ;

SteppingStone5_Recipe recipe1 = new SteppingStone5_Recipe(recipeName,
servings, recipeIngredients, totalRecipeCalories);
recipe1.printRecipe();
}

}

Add a comment
Know the answer?
Add Answer to:
Can someone help me with my code.. I cant get an output. It says I do...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I would like someone to check my code and help with my for loop to print...

    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; }...

  • How to build Java test class? I am supposed to create both a recipe class, and...

    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; /** * *...

  • I'm getting a few errors still under RecipeBox. Would you be able to see what's wrong?...

    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;...

  • Prompt: In this stepping stone lab assignment, you will build a Recipe class, getting user input...

    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 conditiona...

    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...

    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...

    *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; } /** *...

  • This is my current output for my program. I am trying to get the output to...

    This is my current output for my program. I am trying to get the output to look like This is my program Student.java import java.awt.GridLayout; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import javax.swing.JFileChooser; public class Student extends javax.swing.JFrame {     BufferedWriter outWriter;     StudentA s[];     public Student() {         StudentGUI();            }     private void StudentGUI() {         jScrollPane3 = new javax.swing.JScrollPane();         inputFileChooser = new javax.swing.JButton();         outputFileChooser = new javax.swing.JButton();         sortFirtsName = new...

  • JAVA: How do I output all the data included for each employee? I can only get...

    JAVA: How do I output all the data included for each employee? I can only get it to output the name, monthly salary and annual salary, but only from the Employee.java file, not Salesman.java or Executive.java. Employee.java package project1; public class Employee { private String name; private int monthlySalary; public Employee(String name, int monthlySalary) { this.name = name; this.monthlySalary = monthlySalary; } public int getAnnualSalary() { int totalPay = 0; totalPay = 12 * monthlySalary; return totalPay; } public String...

  • please edit my java code perferably on jgrasp version 50.0 , wont complie correctly :( the...

    please edit my java code perferably on jgrasp version 50.0 , wont complie correctly :( the program is supposed to read from my input file and do the following        1) print out the original data in the file without doing anything to it.        2) an ordered list of all students names (last names) alphabetically and the average GPA of all student togther . 3) freshman list in alphabeticalorder by last name with the average GPA of the freshmen...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT