I receive an error illegal start of expression starting at "public class Ingredient {". How would I fix this error?
*
* 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;
/**
*
*
*
* @author jennifer.cook_snhu
*
*/
public class SteppingStone2_IngredientCalculator {
/**
*
* @param args the command line arguments
*
*/
public static void main(String[] args) {
public class Ingredient {
private String nameOfIngredient = "";
private int numberCups = 0;
private int numberCaloriesPerCup = 0;
public Ingredient(String nameOfIngredient, int numberCups,
int numberCaloriesPerCup) {
this.nameOfIngredient = nameOfIngredient;
this.numberCups = numberCups;
this.numberCaloriesPerCup = numberCaloriesPerCup;
}
public String getNameOfIngredient() {
return nameOfIngredient;
}
public int getNumberCups() {
return numberCups;
}
public int getNumberCaloriesPerCup() {
return numberCaloriesPerCup;
}
public double getTotalCalories() {
return numberCaloriesPerCup * numberCups;
}
@Override
public String toString() {
return numberCups + " cups of " + nameOfIngredient + ", total Calories: " + getTotalCalories();
}
}
The correct way of using this is:
Make two class one for the ingredients information and one for print the info or can use in one class also.
Ingredient.java:
public class Ingredient {
private String nameOfIngredient = "";
private int numberCups = 0;
private int numberCaloriesPerCup = 0;
public Ingredient(String nameOfIngredient, int numberCups, int numberCaloriesPerCup) {
this.nameOfIngredient = nameOfIngredient;
this.numberCups = numberCups;
this.numberCaloriesPerCup = numberCaloriesPerCup;
}
public String getNameOfIngredient() {
return nameOfIngredient;
}
public int getNumberCups() {
return numberCups;
}
public int getNumberCaloriesPerCup() {
return numberCaloriesPerCup;
}
public double getTotalCalories() {
return numberCaloriesPerCup * numberCups;
}
@Override
public String toString() {
return numberCups + " cups of " + nameOfIngredient + ", total Calories: " + getTotalCalories();
}
}
SteppingStone2_IngredientCalculator.java:
public class SteppingStone2_IngredientCalculator {
public static void main(String[] args) {
Ingredient ing = new
Ingredient("Apple", 10, 20);
System.out.println(ing.toString());
}
}
sample output:
10 cups of Apple, total Calories: 200.0
I receive an error illegal start of expression starting at "public class Ingredient {". How would...
***Please keep given code intact*** Write a JavaFX application that displays a label and a Button to a frame in the FXBookQuote2 program. When the user clicks the button, display the title of the book that contains the opening sentence or two from your favorite book in the label. FXBookQuote2.java /* * 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...
Hello, How can I make the program print out "Invalid data!!" and nothing else if the file has a grade that is not an A, B, C, D, E, or F or a percentage below zero? I need this done by tomorrow if possible please. The program should sort a file containing data about students like this for five columns: one for last name, one for first name, one for student ID, one for student grade percentage, one for student...
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; }...
1. Write a Java program to count all words in a string. User inputs a string sentence and your program should count the number of words in that string. Test Data: Input the string: The quick brown fox jumps over the lazy dog. Expected Output: Number of words in the string: 9 2. Write a class called ATMTransaction. This class has a variable balance and account number. It has three methods, checkBalance, deposit and withdraws along with constructors getters and...
Course,java
import java.util.ArrayList;
import java.util.Arrays;
/*
* 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 fenghui
*/
public class Course {
private String cName;
private ArrayList<Subject>
cores;
private ArrayList<Major>
majors;
private ArrayList<Subject>
electives;
private int cCredit;
public Course(String n, int cc){
cName = n;
cCredit =
cc;
cores = new
ArrayList<Subject>(0);
majors =...
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; /** * *...
The current code I have is the following: package uml; public class uml { public static void main(String[] args) { // TODO Auto-generated method stub } } class Account { private String accountID; public Account(String accountID) { this.accountID = accountID; } public String getAccountID() { return accountID; } public void setAccountID(String accountID) { this.accountID = accountID; } @Override public String toString() { return "Account [accountID=" + accountID + "]"; } } class SuppliesAccount extends Account { private...
I need help with my code. It keeps getting this error:
The assignment is:
Create a class to represent a Food object. Use the
description provided below in UML.
Food
name : String
calories : int
Food(String, int) // The only constructor. Food name and
calories must be
// specified
setName(String) : void // Sets the name of the
Food
getName() : String // Returns the name of the
Food
setCalories(int) : void // Sets the calories of the
Food...
/* * 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 checkingaccounttest; // Chapter 9 Part II Solution public class CheckingAccountTest { public static void main(String[] args) { CheckingAccount c1 = new CheckingAccount(879101,3000); c1.deposit(350); c1.deposit(220); c1.withdraw(100); c1.deposit(1100); c1.deposit(700); c1.withdraw(350); c1.withdraw(220); c1.withdraw(100); c1.deposit(1100); c1.deposit(700); c1.deposit(1000); System.out.println(c1); System.out.println("After calling computeMonthlyFee()"); c1.computeMonthlyFee(); System.out.println(c1); } } class BankAccount { private int...