-
Notifications
You must be signed in to change notification settings - Fork 0
/
Penguin.java
136 lines (113 loc) · 2.93 KB
/
Penguin.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package ZooManagementSystem;
import java.util.List;
public class Penguin {
private double height;
private int age;
private String name;
private static int LastSortWayused=2; // Defult is by height
private static int LifeSpan= 6;
private int happiness ;
private final String P_noise;
//Constructor
public Penguin(String name, int age, double height) {
this.name = name;
this.age = age;
this.height = height;
this.P_noise= "squack";
this.happiness=100;
}
//Function to Sort the list of the penguies by Hieght
public static List<Penguin> SortByHeight(List<Penguin> arr) {
Penguin temp;
for(int i = 0; i<arr.size()-1 && arr.get(i) != null; i++) {
for(int j = i+1; j < arr.size() && arr.get(j) != null; j++) {
if (arr.get(i).height <= arr.get(j).height) {
temp= arr.get(i);
arr.set(i,arr.get(j));
arr.set(j,temp);
}
}
}
return arr;
}
public static List<Penguin> SortByAge(List<Penguin> arr) {
Penguin temp;
for(int i = 0; i<arr.size()-1 && arr.get(i) != null; i++) {
for(int j = i+1; j < arr.size() && arr.get(j) != null; j++) {
if (arr.get(i).age > arr.get(j).age) {
temp= arr.get(i);
arr.set(i,arr.get(j));
arr.set(j,temp);
}
}
}
return arr;
}
public static List<Penguin> SortByName(List<Penguin> arr) {
Penguin temp;
for(int i = 0; i<arr.size()-1 && arr.get(i) != null; i++) {
for(int j = i+1; j < arr.size() && arr.get(j) != null; j++) {
if (arr.get(j).name.compareTo(arr.get(i).name) > 0 ) {
temp= arr.get(i);
arr.set(i,arr.get(j));
arr.set(j,temp);
}
}
}
return arr;
}
public static int getLastSortWayused() {
return LastSortWayused;
}
public static void setLastSortWayused(int lastSortWayused) {
LastSortWayused = lastSortWayused;
}
// Deleting a fish after it was eaten by a penguin
public AquariumFish[] Feed_Penguins(AquariumFish[] fishes){
AquariumFish[] temp= new AquariumFish[fishes.length-1];
int i=0;
while(fishes[i+1]!=null){
temp[i]=fishes[i];
i++;
}
// Removing from the aquarium the last fish that was eaten
AquariumFish Fish_to_eat = fishes[i];
if(Fish_to_eat!=null)
System.out.println("Successfully deleted " + Fish_to_eat);
return temp;
}
public double feed() {
return 1.0;
}
public String makeNoise(){
return P_noise;
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getHappiness() {
return happiness;
}
public void setHappiness(int happiness) {
this.happiness = happiness;
}
public boolean ageOneYear(){
this.age+=1;
return this.age <= LifeSpan;
}
}