public class PitcherUtil {
public static double ERA(Pitcher p) {
if (p.inningsPitched > 0) {
return p.runsScored / p.inningsPitched * 9; // 9 innings per game
}
return 0.0;
}
}
The dot operator (.
) is used to sort of "burrow into" (or de-reference, if you want to get technical)
an object, and access its data or behaviour. In this case, we access various pieces of data like inningsPitched
and runsScored
from the Pitcher p
.
The dot operator (.
) is used to sort of "burrow into" (or de-reference, if you want to get technical)
an object, and access its data or behaviour. In this case, we access various pieces of data like inningsPitched
and runsScored
from the Pitcher p
.
Since the Pitcher
's instance variables are public
,
we can access them directly from the p
variable, by using the
dot operator.
Since the Pitcher
's instance variables are public
,
we can access them directly from the p
variable, by using the
dot operator.
This method's purpose is to calculate the earned run average for
a given Pitcher
. Since the Pitcher
is currently only holding data,
but no behaviours, we implement behaviours for the Pitcher
in separate
functions that must take the Pitcher
as a parameter.
This method's purpose is to calculate the earned run average for
a given Pitcher
. Since the Pitcher
is currently only holding data,
but no behaviours, we implement behaviours for the Pitcher
in separate
functions that must take the Pitcher
as a parameter.
This is where behaviours are defined for Pitchers.
This is where behaviours are defined for Pitchers.