Page 253 - Introduction to Programming with Java: A Problem Solving Approach
P. 253
6.10 The return Statement 219
1 /*****************************************************************
2 *
3 *
4*
5
Mouse2.java
Dean & Dean
This class models a mouse for a growth simulation program.
*****************************************************************/
6
7
8
import java.util.Scanner;
9
10
public class Mouse2
11
{
12
private int age = 0;
private double weight = 1.0;
13
// age in days
// weight in grams
private double percentGrowthRate; // % daily weight gain
//**************************************************************
public void setPercentGrowthRate(double percentGrowthRate)
{
14
15
16
17
18
19
*
20
this.percentGrowthRate = percentGrowthRate;
} // end setPercentGrowthRate
parameter
21
22
23
//**************************************************************
Apago PDF Enhancer
public int getAge()
24
25
26
{
27
return this.age;
} // end getAge
28
29
30
//**************************************************************
31
32
public double getWeight()
33
{
34
return this.weight;
} // end getWeight
35
36
parameter
//**************************************************************
37
38
39
public void grow(int days)
40
{
}
local variable
41
for (int i=0; i<days; i++)
42
{
43
this.weight +=
44
(0.01 * this.percentGrowthRate * this.weight);
45
}
46
this.age += days;
47
// end grow
48
}
// end class Mouse2
Figure 6.14
Mouse2 class