-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRabbit.java
More file actions
153 lines (130 loc) · 3.73 KB
/
Copy pathRabbit.java
File metadata and controls
153 lines (130 loc) · 3.73 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
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
import java.util.*;
/**
* This program simulates the growth of a bunny population starting with a fixed amount of does and bucks.
* This is the Rabbit.java file and it contains the properties of rabbits that the RabbitSimulation will refer to.
* @author Wei Zhong Tee
* @since 16 February 2020
*/
public class Rabbit {
private String gender;
private String sex;
private int age = 0;
private int gestation = 0;
private int litterCount = 0;
private int gestation_period;
private int postPregnancyDaysRemaining = 0;
private int random;
public Rabbit() {
}
/**
* This is an overloaded constructor that is used for adding the Rabbit's sex to the ArrayList of type <rabbit>
* @param in is the string that determines the rabbit's gender
*/
public Rabbit(String in) {
gender = in;
age = 0;
}
/**
* This method is used so that RabbitSimulation.java can access the strings in the ArrayList of type <Rabbit>
* @return gender "M" or "F" to determine gender.
*/
public String toString() {
return gender.toString();
}
/**
* This method is used to generate random numbers to determine sex or the amount of litters a doe can have.
* @param a is the number that tells the method how many random variables it needs.
* @return int is the random number that is used for determining sex or amount of litters.
*/
public int getRandom(int a) {
Random rand = new Random();
random = rand.nextInt(a);
return random;
}
/**
* This method is used to generate random numbers to determine how long the pregancy is
* Based on what is generated by getRandom(), the appropriate amount of pregancy days between 28 and 32 will be set for female rabbits.
* @return int number of days a doe is pregnant for.
*/
public int getGestationPeriod() {
int size = getRandom(5);
if (size == 0) {
gestation_period = 28;
}
if (size == 1) {
gestation_period = 29;
}
if (size == 2) {
gestation_period = 30;
}
if (size == 3) {
gestation_period = 31;
}
if (size == 4) {
gestation_period = 32;
}
return gestation_period;
}
/**
* This method is used to generate the random amount of litters a doe can have .
* @return int the amount of litters born in one birth event.
*/
public int getLitterCount() {
int size = getRandom(6);
if (size == 0) {
litterCount = 3;
}
if (size == 1) {
litterCount = 4;
}
if (size == 2) {
litterCount = 5;
}
if (size == 3) {
litterCount = 6;
}
if (size == 4) {
litterCount = 7;
}
if (size == 5) {
litterCount = 8;
}
return litterCount;
}
/**
* This method is used to generate the sex of the litters born.
* @return String the sex of each litter born, "M" or "F".
*/
public String getSex() {
int size = getRandom(2);
if (size == 0) {
sex = "M";
}
if (size == 1) {
sex = "F";
}
return sex;
}
/**
* This method is used for incrementing a rabbit's age every year.
* @param a is the number of the current year so that 1 can be added to the existing age (days).
*/
public void addAge(int a) {
age = a + 1;
}
/**
* After adding the age in the previous method, this method is to get the new age back in RabbitSimulation.java
* @return int the new age of each rabbit.
*/
public int getAge() {
return age;
}
/**
* This method is used for resetting all rabbit properties before a new trial begins.
*/
public void resetAll() {
age = 0;
gestation = 0;
postPregnancyDaysRemaining = 0;
}
}