-
Notifications
You must be signed in to change notification settings - Fork 0
/
FishTank.java
84 lines (65 loc) · 2.47 KB
/
FishTank.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
import java.util.*;
public class FishTank {
protected double temperature, pH, volume, lighting; // #3 double
protected int numberOfFish, bacteriaColony; // #3 int
protected double[] dimensions;
protected ArrayList<Organism> organisms; // #13 ArrayList
public FishTank() {
temperature = 78.0;
pH = 7.0;
volume = 0.0;
lighting = 0.0;
numberOfFish = 0;
bacteriaColony = 0;
dimensions = new double[3];
for(int i = 0; i < 4; i++) dimensions[i] = 0;
organisms = new ArrayList<>();
}
public FishTank(double temp, double pH, double lighting, double[] dimensions, ArrayList<Organism> organisms, int numberOfFish, int bacteriaColony) {
temperature = temp;
this.pH = pH;
this.volume = volume;
this.lighting = lighting;
this.dimensions = new double[3];
for(int i = 0; i < dimensions.length; i++)
this.dimensions[i] = dimensions[i];
volume = calcVolume();
this.organisms = new ArrayList<Organism>();
this.organisms = organisms;
this.numberOfFish = numberOfFish;
this.bacteriaColony = bacteriaColony;
}
// getters
public double getTemperature() { return temperature; }
public double getpH() { return pH; }
public double getSize() { return volume; }
public double getLighting() { return lighting; }
public double[] getDimensions() { return dimensions; }
public ArrayList<Organism> getLivestock() { return organisms; }
public int getNumberOfFish() { return numberOfFish; }
public int getBacteriaColony() { return bacteriaColony; }
// setters
public void addOrganism(Organism organism) {
organisms.add(organism);
if(organism.getType().equals("fish"))
numberOfFish++;
}
public void removeOrganism(Organism organism) {
if(organism.getType().equals("fish"))
numberOfFish--;
organisms.remove(organisms.indexOf(organism));
}
public void setBacteriaColony(int change) { bacteriaColony = change; }
public void changeTemp(int newTemp) { temperature = newTemp; }
public void setpH(double newpH) { pH = newpH; }
// other methods
public double calcVolume() {
double vol = dimensions[0]*dimensions[1]*dimensions[2]*0.004329;
return vol;
}
public boolean getCompatibility() {
if(numberOfFish > (int) volume) // #8 casting
return false;
return true;
}
}