Java Reference
In-Depth Information
Notice that when isFactor( ) is called, the arguments are also separated by commas.
When using multiple parameters, each parameter specifies its own type, which can differ
from the others. For example, this is perfectly valid:
Adding a Parameterized Method to Vehicle
You can use a parameterized method to add a new feature to the Vehicle class: the ability
to compute the amount of fuel needed for a given distance. This new method is called fuel-
needed( ) . This method takes the number of miles that you want to drive and returns the
number of gallons of gas required. The fuelneeded( ) method is defined like this:
Notice that this method returns a value of type double . This is useful since the amount of
fuel needed for a given distance might not be a whole number. The entire Vehicle class that
includes fuelneeded( ) is shown here:
Search WWH ::




Custom Search