Witam. Dopiero uczę się programowania Pracuje obecnie nad następującym ćwiczeniem:
//We are going to model a ship for transporting cars over the canal.
- This ship has a maximum capacity of 100 places.
- A second limitation is that the maximum weight that can be supported is 95000 kg.
• We are going to model two kind of vehicles. - A car has a weight of 1000 kg and takes one place.
- A van has a weight of 1500 kg and takes two places.
• Create a class Ship.
• Create the variables necessary to hold the information of the ship.
• Write a method addVehicle(Vehicule aVehicule) to add a vehicule into the ship.
• Write a method totalWeight() that returns the total weight of the content of the ship.
• Write a method removeVehicle() to remove the last added vehicle
• Write a method getContent() to check the content of the ship (return a String). - for example : "2500 kg and 25 places"
• When adding or removing cars to your ship, pay attention to the maximum total number of cars and the maximum total weight.//
Do dodawania obiektów chce użyć ArrayList i wykorzystać metodę <add>. Jednakże nie wiem jak sobie poradzić ze sprawdzaniem czy tablica jest tuz pełna i jak ograniczyć dodawanie obiektów kiedy przekroczy capacity i weight. Będę bardzo wdzięczna za pomoc.