You are on page 1of 4

OOP Lab 4

Pranabesh Kumar Paul


Id: 21-45760-3

Food:
public class Food {
String name;
String[] ingredients= {"Chicken","Folur","Hot Sauce"};

double price;
float calories;
Food(){

public void setName(String name) {


System.out.println("Name:"+name);

void setIngredients(String[]ingredients) {
System.out.print("Ingredients:");

for(int i=0;i<ingredients.length;i++) {
System.out.print(ingredients[i]+" ");

void setPrice(double price) {


System.out.println("Price:"+price);

}
void setCalories(float calories) {
System.out.println("Calories:"+calories);
}
void removeIngredient(String ingredient) {

for(int x = 0;x<=2;x++) {
if(ingredients[x]==ingredient) {
ingredients[x] = null;

}
else {
System.out.print(ingredients[x]+" ");
continue;

}
}
}

public void addIngredient(String ingredient) {

for(int y= 0;y<=2;y++) {
if(ingredients[y]==null) {
ingredients[y] = ingredient;

}
else {System.out.print(ingredients[y]+" ");

continue;
}
}
}

void showDetails(String name,double price,float calories) {

}
Start:
import java.util.*;

public class Start {


public static void main(String args[]) {
String[] ingredients= {"Butter","Ice","Vanilla"};
Food x=new Food();
Food y=new Food();
System.out.print("Name,price,calories:\n");
Scanner Name = new Scanner(System.in);
String name=Name.nextLine();
Scanner Price = new Scanner(System.in);
double price=Price.nextDouble();
Scanner Calories = new Scanner(System.in);
float calories=Calories.nextFloat();
System.out.println();

x.setName(name);
x.setCalories(calories);
y.setPrice(price);
y.setIngredients(ingredients);
System.out.print("\nAfter remove:");
x.removeIngredient("Butter");
System.out.print("\nAfter add:");
y.addIngredient("Butter");

}
Result:

You might also like