File size: 1,627 Bytes
7b4a862
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
In the program, the class Recipe is defined. 

Define the following attributes for the class:
String type: dish
Integer types:  cookingtime and portions
String-type list: ingredients





import java.util.Random;
import java.util.ArrayList;

public class Test{
    public static void main(String[] args){
        System.out.println("Testing forming objects...");
        
        ArrayList<String> ai1 = new ArrayList<>();
        ArrayList<String> ai2 = new ArrayList<>();
        
        ai1.add("water");
        ai1.add("salt");
        ai1.add("oats");
        
        ai2.add("tomatoes");
        ai2.add("cucumber");
        ai2.add("salad");
        
        Recipe porridge = new Recipe("Porridge", 15, 2, ai1);
        Recipe salad = new Recipe("Salad", 5, 1, ai2);
        
        System.out.println(porridge);
        System.out.println(salad);
    }
}

class Recipe {

    //ADD ATTRIBUTES
    String dish;
    int cookingtime;
    int portions;
    ArrayList<String> ingredients;




    //CONSTRUCTOR
    
    public Recipe(String d, int ct, int p, ArrayList<String> ing) {
        this.dish = d;
        this.cookingtime = ct;
        this.portions = p;
        this.ingredients = ing;
    }

    @Override
    public String toString() {
        return "Recipe [dish=" + dish + ", cooking time=" + cookingtime + ", portions=" + portions
                + ", ingredients=" + ingredients + "]";
    }
}





Testing forming objects...
Recipe [dish=Porridge, cooking time=15, portions=2, ingredients=[water, salt, oats]]
Recipe [dish=Salad, cooking time=5, portions=1, ingredients=[tomatoes, cucumber, salad]]