You are on page 1of 1

7487219Y

E.K.

a)
public static int totalPointsEarned (int numFlights)
{
int totalMiles = numFlights * milesTraveled();
int points = 0;
if (totalMiles > 10000)
{
points += 1000;
totalMiles -= 1000;
points += 18000;
totalMiles -= 9000;
points += 5 * totalMiles;
}
else if (totalMiles <= 10000 && totalMiles > 1000)
{
points += 1000;
totalMiles -= 1000;
points += 2 * totalMiles;
}
else if (totalMiles <= 1000)
{
points = totalMiles;
}
return points;
}

b)
In order to make a maximum value without changing the signature of
totalPointsEarned,
a variable will first need to be made, such as "int maxPoints". Additionally, a
mutator method will need to be added as well, such as "changeMaxPoints(int new)"
which
will change the max value to value "new". In order to incorporate it, a new method
could be added,
which checks if the points are over a certain threshold which will be called in
tangent to the
"totalPointsEarned()". So, after calculating the points, the max value checker
method will be called,
and if the points returned is over the threshold, it will just be set to the max
value. This avoids
the problem of changing the method and makes the process a lot of smoother.

You might also like