Java Reference
In-Depth Information
Display 4.6
A Formal Parameter Used as a Local Variable
(part 1 of 2)
This is the file
Bill.java
.
1
import
java.util.Scanner;
2
public
class
Bill
3{
4
public static double
RATE = 150.00; //Dollars per quarter hour
5
private
int
hours;
6
private
int
minutes;
7
private
double
fee;
8
public void
inputTimeWorked()
9
{
10
System.out.println("Enter number of full hours worked");
11
System.out.println("followed by number of minutes:");
12
Scanner keyboard =
new
Scanner(System.in);
computeFee
uses the
parameter
minutesWorked
as a local variable.
13
hours = keyboard.nextInt();
14
minutes = keyboard.nextInt();
15
}
16
public double
computeFee(
int
hoursWorked,
int
minutesWorked)
17
{
18
minutesWorked = hoursWorked*60 + minutesWorked;
19
int
quarterHours = minutesWorked/15; //Any remaining fraction of a
20
// quarter hour is not charged for.
21
return
quarterHours*RATE;
Although
minutes
is plugged in
for
minutesWorked
and
minutesWorked
is changed, the
value of
minutes
is not changed.
22
}
23
public void
updateFee()
24
{
25
fee = computeFee(hours, minutes);
26
}
27
public void
outputBill()
28
{
29
System.out.println("Time worked: ");
30
System.out.println(hours + " hours and " + minutes + " minutes");
31
System.out.println("Rate: $" + RATE + " per quarter hour.");
32
System.out.println("Amount due: $" + fee);
33
}
34
}