0% found this document useful (0 votes)
24 views4 pages

Assignmetn 2 Task 2

Uploaded by

furqanacc5785
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views4 pages

Assignmetn 2 Task 2

Uploaded by

furqanacc5785
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

import java.util.

ArrayList;

class Date {
private int date;
private int month;
private int year;

Date(int date, int month, int year) {


this.month = month;
this.date = date;
this.year = year;
}

public String get_date() {


return "" + date + "/" + month + "/" + year; // Return date in proper
format
}
}

class contest {
Date date;
int won_prize;

contest(Date date, int won_prize) {


this.date = date;
this.won_prize = won_prize;
}

public void get_data() {


System.out.println("the date of the contest is : " + date.get_date()); //
Use get_date() method
}

public void get_won_prize() {


System.out.println("the winning prize of the contest is : " + won_prize);
}
}

class Recepie {
private String name;
private String description;
private String ingrediants;
private String instruction;
private int rate;

public Recepie(String name, String description, String ingrediants, String


instruction) {
this.name = name;
this.description = description;
this.ingrediants = ingrediants;
this.instruction = instruction;
}

public String get_recipie() {


return "\nthe name of recipe is : " + name + "\nDescription : " +
description + "\nIngredients : " + ingrediants + "\nInstruction : " + instruction;
}
public void rate(int rating) {
this.rate = rating;
}
}

abstract class Chef {


protected int chef_id;
protected Recepie [] recepies;
protected int [] rate_recepie;
// protected int [] rate_chef;
protected String type;
protected int rate;

Chef(int chef_id, String type) {


this.chef_id = chef_id;
this.type = type;
// this.recepies = new ArrayList<>(); // Initialize the ArrayList
// this.recepies.add(recepie); // Add the initial recipe
// this.rate = rate;
}
public void rate(int rating) {
this.rate = rating;
}
public void printRating() {
System.out.println("Chef ID: " + chef_id + ", Chef Type: " + type + ", Chef
Rating: " + rate);
}
// public void get_rating(Chef ...c1)
// {
// for(Chef chef : c1)
// {
// System.out.println("the rating of chef with id : "+chef_id + "is :
" );
// }
// }
}

class senior_chef extends Chef {


private int year_of_experience;

senior_chef(int chef_id, String type, int year_of_experience) {


super(chef_id, type); // Call the constructor of the superclass
this.year_of_experience = year_of_experience;
this.recepies = new Recepie[3]; // Initialize the recepies array
}
public String add_recepies(Recepie one , Recepie two , Recepie three )
{
if (recepies[0] == null && recepies[1] == null && recepies[2] == null) { //
Check if all slots are empty
recepies[0] = one;
recepies[1] = two;
recepies[2] = three;
return "Recipes added successfully";
} else {
return "Failed to add recipes: Not enough space available";
}
}
public String add_recepies(Recepie one , Recepie two )
{
if (recepies[0] == null && recepies[1] == null ) { // Check if all slots
are empty
recepies[0] = one;
recepies[1] = two;

return "Recipes added successfully";


} else {
return "Failed to add recipes: Not enough space available";
}
}
public String add_recepies(Recepie one )
{
if (recepies[0] == null ) {
recepies[0] = one;
return "Recipes added successfully";
} else {
return "Failed to add recipes: Not enough space available";
}
}
public void get_recipes() {
System.out.println("the recipes of senior are : ");
for (int i = 0; i < recepies.length; i++) {
if (recepies[i] != null) {
System.out.println("" + recepies[i].get_recipie());
}
}
}
public void printRating() {
System.out.println("Chef ID: " + chef_id + ", Chef Type: " + type + ", Chef
Rating: " + rate);
}
}
class junior_chef extends Chef
{
senior_chef supervisor;
junior_chef(int shef_id , String type , senior_chef supervisor_id)
{
super(shef_id , type );
this.supervisor = supervisor_id;
this.recepies = new Recepie[1];
}
public String add_recepies(Recepie one )
{
if (recepies[0] == null ) {
recepies[0] = one;
return "Recipes added successfully";
} else {
return "Failed to add recipes: Not enough space available";
}
}
public void get_recipes() {
for (int i = 0; i < recepies.length; i++) {
if (recepies[i] != null) {
System.out.println("the recipes of juniors are : " +
recepies[i].get_recipie());
}
}
}
public void printRating() {
System.out.println("Chef ID: " + chef_id + ", Chef Type: " + type + ", Chef
Rating: " + rate);
}
}

public class Cooking_contest


{
public static void main(String [] a)
{
Date d1 = new Date (12 , 12 , 2024);
contest c1 = new contest(d1, 25000);
c1.get_data();
c1.get_won_prize();
System.out.println("____________________");
senior_chef s1 = new senior_chef(1, "senior" , 12 );
Recepie r1 = new Recepie("Pulao", "Delicious", "Rice, Spices", "Cook until
done");
Recepie r2 = new Recepie("Pasta", "Tasty", "Pasta, Sauce", "Boil and
serve");
Recepie r3 = new Recepie("Salad", "Refreshing", "Lettuce, Tomato", "Mix and
enjoy");

s1.add_recepies(r1 , r2 , r3);
s1.get_recipes();
System.out.println("\n\n\n");
junior_chef j1 = new junior_chef(2 , "junior" , s1);
j1.add_recepies(r1);
j1.get_recipes();
System.out.println("\n\n\nnow we are rating the recipies\n");

// we need to rate te chefs


s1.rate(6);
j1.rate(8);
s1.printRating();
j1.printRating();

}
}

You might also like