abstract methods and classes, need help and guidance very bad.
I am trying to complete this task and I am to a certain point I need some guidance.
my first task is as follows..........
task: Develop an abstract class called Recipe with the following elements:
• Instance Data: number of servings (an integer)
• Constructor method which accepts number of servings as a parameter, and assigns it to the instance variable.
• An abstract method named setIngredients, which accepts a String array as a parameter.
if anyone sees something I can improve or that would create an error. I am looking for help and criticism on how I can do this better or fix it.
and my code:
Code:
public abstract class Recipe {
int numservings;
String cookTime;
int cookTemperature;
public Recipe(int numservings){
this.numservings = 6;
}
public abstract void setingredients();
}
my next task is as follows.....
second task: Develop another class called CookieRecipe which extends Recipe. Include the following:
• Instance Data: cookTime (a String); cookTemperature(an integer); ingredientList [] (a String array)
• A Constructor which receives number of servings as a parameter, and then passes it to the constructor of the parent class using super.
• setIngredients method which receives a String array representing a list of ingredients.****NEED HELP WITH THIS
• Two other “setters” – for cookTime and cookTemperature
• A toString method to print a description of the object, including the ingredient list, the cookTime and the cookTemperature.*****ALSO NEED HELP WITH THIS
Code:
public class CookieRecipe extends Recipe{
String ingredients;
String cookTime = "20 minutes";
int cookTemperature = 325;
int numservings;
public CookieRecipe(int cookTemperature, String cookTime){
super(cookTime, cookTemperature);
System.out.printf("Cookie Recipe ingredients for PeanutButter Cookies are %s\n", this);
}
public String toString(String cookTime, int cookTemperature, int numservings){
this.toString(cookTime, cookTemperature, numservings);
return String.format("%s %s %s %s", getingredients(), cookTime, cookTemperature, numservings);
}
@Override
public void setingredients() {
String[] ingredientList= new String[6];
ingredientList[0] = "Flour";
ingredientList[1] = "Sugar";
ingredientList[2] = "Peanutbutter";
ingredientList[3] = "Baking powder";
ingredientList[4] = "Raisins";
ingredientList[5] = "Vanilla";
}
public String getingredients(){
return ingredients;
}
public void setcookTime(String cookTime){
this.cookTime = cookTime;
}
public String getcookTime(){
return cookTime;
}
public void setcookTemperature(int cookTemperature){
this.cookTemperature = cookTemperature;
}
public int getcookTemperature(){
return cookTemperature;
}
}
Last task is as follows.... I need a lot of help on this one.......
TASK: Create the “Driver” class, named RecipeDriver, consisting of a main method which does the following:
• Create a String array of the ingredients, for example: "sugar", "milk", "raisins", etc. Each ingredient is an element of the array.
• Instantiate a CookieRecipe object
• Call the setIngredients method, passing the array of ingredients.
• Call the setCookTime and setTemperature methods, passing as arguments the time and temperature from your recipe, respectively.
• Print the instantiated object (using your toString method description)
And the code I have is ......
Code:
public class RecipeDriver {
public static void main(String[] args) {
Recipe recipe = new CookieRecipe(6, "20 Minutes");
}
//public static void ingredients(String x[]){
//x= IngredientList[0]
//}
}