-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLion.java
57 lines (50 loc) · 1.5 KB
/
Lion.java
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
package com.ioannis.unipiZoo;
public class Lion extends Animal {
private String gender;
private static int counter=0; //static because it has to count the instances of this specific class in order to give different id to each instance
public Lion(String name, String homotaxy, double weight, int age, String gender) {
super(name, homotaxy, weight, age);
this.gender = gender;
setClassname("lion");
counter+=1;
if (counter < 100) setId("li"+00+counter);
else if (counter >= 100) setId("li"+00+counter);
}
@Override
public String getGender() {
return gender;
}
@Override
public void setGender(String gender) {
this.gender = gender;
}
@Override
public void makeSound()
{
System.out.println("-roar roar roar roar-");
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@Override
public void rarity()
{
if (counter<3)
System.out.println("animal is rare in our zoo");
else
System.out.println("animal is common in our zoo");
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@Override
public String toString() {
return super.toString() +
"gender='" + gender + '\'' +
'}';
}
}