class Food {
private String name;
private String []ingredients;
private double price;
private float calories;
public Food (){
}
public Food (String name, String [] ingredients, double price, float calories){
this.name= name;
this. ingredients= ingredients;
this.price=price;
this.calories= calories;
}
public void setName(String name){
this.name=name;
}
public void setIn(String[] ingredients){
this.ingredients=ingredients;
}
public void setPrice (double price){
this.price= price;
}
public void setCalories(float calories){
this.calories = calories;
}
public String getName(){
return name;
}
public String[] getIn(){
return ingredients;
}
public double getPrice(){
return price;
}
public float getCalories(){
return calories;
}
}
class Burger extends Food {
private int numberofPatty;
public Burger(){
}
public Burger(String name, String[] ingredients, double price,float calories, int numberofPatty){
super(name,ingredients,price,calories);
this.numberofPatty= numberofPatty;
}
public void setNP(int numberofPatty){
this.numberofPatty= numberofPatty;
}
public int getNP(){
return numberofPatty;
}
public void showdetails(){
System.out.println("Name="+getName());
System.out.println("In="+ getIn());
System.out.println("Price="+getPrice());
System.out.println("Calories="+getCalories());
System.out.println("NP="+numberofPatty);
}
}
public class Main {
public static void main(String[] args) {
String[] burgerIngredients = new String[2];
burgerIngredients[0]= new String("alu");
burgerIngredients[1]= new String("Potato");
Burger burger1 = new Burger("Classic Burger", burgerIngredients, 5.99, 550, 1);
burger1.showdetails();
}
}
thats the burger class, showdetails is the output i want
i tried array concept. what should i do to get the output with ingredients name?.........................................................................................................................................................................
You can use get method to print all ingredient details.
It would be helpful if you can show burger class like using showdetails() u wanted to print ingredient details?