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

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

  • I need help with adding comments to my code and I need a uml diagram for...

    I need help with adding comments to my code and I need a uml diagram for it. PLs help.... Zipcodeproject.java package zipcodesproject; import java.util.Scanner; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class Zipcodesproject { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner input=new Scanner(System.in); BufferedReader reader; int code; String state,town; ziplist listOFCodes=new ziplist(); try { reader = new BufferedReader(new FileReader("C:UsersJayDesktopzipcodes.txt")); String line = reader.readLine(); while (line != null) { code=Integer.parseInt(line); line =...

  • I am working on integrating a database to an Android application for a course. Currently, I have all the database code done, but getting all of the EditText fields to enter data into the database has...

    I am working on integrating a database to an Android application for a course. Currently, I have all the database code done, but getting all of the EditText fields to enter data into the database has me stuck. Assignment objectives here, so we can be on the same page: Create a second page with a data entry form and the following fields: recipename, category, ingredients, and instructions. Make the Category field a dropdown box that contains the recipe categories listed...

  • Java Branches code not working please HELP!! I am trying to build this class that will...

    Java Branches code not working please HELP!! I am trying to build this class that will ask for an ingredient, and the number of cups of the ingredient. It should then branch into an if/else branch off to verify that the number entered is valid and that it is within range. Once that branch completes it should then continue on to ask for the calories per cup, and then calculate total calories. Once I get it to enter the branch...

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

  • Please fix my code so I can get this output: Enter the first 12-digit of an...

    Please fix my code so I can get this output: Enter the first 12-digit of an ISBN number as a string: 978013213080 The ISBN number is 9780132130806 This was my output: import java.util.Scanner; public class Isbn { private static int getChecksum(String s) { // Calculate checksum int sum = 0; for (int i = 0; i < s.length(); i++) if (i % 2 == 0) sum += (s.charAt(i) - '0') * 3; else sum += s.charAt(i) - '0'; return 10...

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
ADVERTISEMENT