-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava_7.java
More file actions
59 lines (51 loc) · 1.5 KB
/
java_7.java
File metadata and controls
59 lines (51 loc) · 1.5 KB
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
public class java_7 {
public static void main(String[] args) {
Cat[] arrCat = {
new Cat("Barsik", 3, false),
new Cat("Murzik", 8, false),
new Cat("Tabasik", 12, false)
};
Plate plate = new Plate(500);
System.out.println("Кол-во еды: " + plate);
// if (plate > 23) {
for (Cat arrcat : arrCat) {
arrcat.eat(plate);
System.out.println(arrcat);
}
//}
System.out.println("после кормежки осталось: " + plate);
}
}
class Cat {
private String name;
private int appetite;
private boolean satiety;
Cat(String name, int appetite, boolean satiety) {
this.name = name;
this.appetite = appetite;
this.satiety = satiety;
}
void eat(Plate plate) {
plate.dicreaseFood(appetite);
}
@Override
public String toString() {
return name + " " + "съел - " + appetite + " " + "Голодный? - " + satiety;
}
}
class Plate {
private int food;
Plate(int food) {
this.food = food;
}
void dicreaseFood(int food) {
this.food -= food;
}
void increaseFood(int food) {
this.food += food;
}
@Override
public String toString() {
return "" + food;
}
}