-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAquariumFish.java
155 lines (119 loc) · 3.34 KB
/
AquariumFish.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package ZooManagementSystem;
import java.util.Arrays;
import java.util.stream.Collectors;
public class AquariumFish {
private int age;
private double length;
private Colour[] colours;
private Pattern pattern;
private int happiness;
private static int LifeSpan= 25;
private final String Fish_Noise = "blob";
//Default Constructor
public AquariumFish() {
age = 0;
length = 0;
}
//Constructor
public AquariumFish(int age, double length) {
this.age = age;
this.length = length;
this.happiness=100;
}
public static void ZooDetails() {
}
public double HowMuchMealFish(){
if (this.age<3)
return 3;
else
return length + 3;
}
public double feed() {
return HowMuchMealFish();
}
//Returns an integer array with the length of (10) each value is UNIQUE (between 0-9).
public static int[] randomNumberArray() {
int[] randomNumArray = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
for(int i = 0; i < randomNumArray.length; i++) {
int num = (int)(Math.random()*10);
for(int j = 0; j < randomNumArray.length-1; j++) {
while(num == randomNumArray[j]) {
num = (int)(Math.random()*10);
j=0;
}
}
randomNumArray[i] = num;
}
return randomNumArray;
}
//Returns an Enum of a RANDOM array with UNIQUE colour values, each array is formed with the length between 1 to 10 (including).
//the array indicates the colour(s) of the fish(object) it belongs to.
public static Colour[] randomColour() {
Colour[] allColours = Colour.values();
Colour[] singularFishColours = new Colour[(int)(Math.random()*10)+1];
int[] randomUniqueNumberArray = randomNumberArray();
for(int i = 0; i<singularFishColours.length; i++) {
singularFishColours[i] = allColours[randomUniqueNumberArray[i]];
Zoo.numOfFishColours[randomUniqueNumberArray[i]]++;
}
return singularFishColours;
}
//Returns a random enum value of pattern.
public static Pattern randomPattern() {
Pattern[] ranPat = Pattern.values();
return ranPat[(int)(Math.random()*ranPat.length)];
}
public double getLength() {
return length;
}
public void setLength(double length) {
this.length = length;
}
public int getAge() {
return age;
}
public Pattern getPattern() {
return pattern;
}
public void setAge(int age) {
this.age = age;
}
public void setPattern(Pattern pattern) {
this.pattern = pattern;
}
//Returns a String of the Fish's colours.
public String getColours() {
String x = "";
for(int i = 0; i < colours.length; i++) {
x+=colours[i]+ " ";
}
return x;
}
// Using stream and distinct to remove duplicates when we want to show all the fishes
public static String removeDuplicateWords(String inputString) {
String[] words = inputString.split("\\s+");
String result = Arrays.stream(words)
.distinct()
.collect(Collectors.joining(" "));
return result;
}
public void setColours(Colour[] colours) {
this.colours = colours;
}
public String makeNoise(){
return Fish_Noise;
}
public String toString() {
return "Fish.";
}
public int getHappiness() {
return happiness;
}
public void setHappiness(int happiness) {
this.happiness = happiness;
}
public boolean ageOneYear(){
this.age+=1;
return this.age <= LifeSpan;
}
}