vendredi 24 février 2017

Method for counting the value of multiple objects and adding them together

We are making a project about vehicles. We already made an abstract class named vehicleCollection which purpose is to count number of seats of all the vehicles. Then we have 3 subclasses, Car, Bike and Bus. There also has to be a CarCollection class only counting seats of all the cars. Our problem is how to make the method for counting seats.

We have setters and getters for the object of the vechicle, but we cant figure out how to write the method just counting carseats.

We are pretty sure we have to use a for-loop combined with a if-statement, to get the outcome, but the execution is what we're struggeling with.

Does anyone know what would be the best way to write this method?

Also, do we have to add an array-list holding the vechicles, and if yes, where do we put it?

If you have a hard time understanding what I have written, please ask me to elaborate! Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire