|
RHS |
In this exercise we're going to perform some calculations on an array of Bicycle's (a mixture of CityBike's and SportsBike's).
The following application creates an array, coll, with room for 10 Bicycle's. It initialises the array using the method init().
Then it prints the result from 5 methods - you are to implement these methods.
In the following you can assume that ALL Bicycles have been rented out for 4 hours (you need to pass the number of hours to the method that calculates the rent for the individual bicycles)
The first method should calculate the total rent for the CityBike's.
The second method should calculate the total rent for the SportsBike's.
The third method should calculate the total rent for all the Bicycle's.
The fourth method should calculate the number of bicycles that is equipped
with a baby-seat.
The fifth method should calculate the average number of gears for the SportsBike's.
Below is a template for the application - only the body for the 5 methods are missing. You can download the template here: TouristicRental3.java
| import java.util.*;
public class TouristicRental3 { public double cityRent(Bicycle[] list) { public static void init() { |
|---|
Question 5
Implement the 5 methods.
Question 6
What if we declared an array more : private static SportsBike[] sports
= new SportsBike[2];
Then we put two objects of the type SportsBike in the array.
Would we be able to activate the 5 methods using the array sports as argument
(e.g. double x = totalRent(sports); )?
Answer before you adapt the code and try. Then adapt and try. Did you give
the correct answer?