1. A parameterized constructor taking 4 arguments for bread slices, cheese slices, meat patty number and tomato slices. The values of the rest of the variables will be initialized by default to true 2. Another parameterized constructor that takes argument for each of these variables and initializes them accordingly 3. Another parameterized constructor that takes argument for each of these variables and initializes them accordingly 4. Provide setters for mustard, ketchup, iceberg and gilled 5. Provide getters for each of these variables 6. Provide a method calculatePrice() that calculates and returns the price of this sandwich according to the rates given in the above table.
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
}
}
class Food{
private int bread_slices;
private int cheese_slices;
private int meat_patty_number;
private int tomato_slices;
private int mustard;
private int ketchup;
private int iceberg;
private int gilled;
public Food(int b,int c,int m,int t){
bread_slices=b;
cheese_slices=c;
meat_patty_number=m;
tomato_slices=t;
}
public void setMustard(int m){
mustard=m;
}
public void setKetchup(int k){
ketchup=k;
}
public void setIceberg(int i){
iceberg=i;
}
public void setGilled(int g){
gilled=g;
}
public int getMustard(){
return mustard;
}
public int getKetchup(){
return ketchup;
}
public int getIcberg(){
return iceberg;
}
public int getGilled(){
return gilled;
}
public int calculatePrice(){
Scanner in=new Scanner(System.in);
int price;
System.out.print("Enter total price: ");
price=in.nextInt();
return price;
}
}
Comments
Leave a comment