March 2018
Intermediate to advanced
208 pages
4h 52m
English
| | class Inventory { |
| » | // Fields (we only have one) |
| » | List<Supply> supplies = new ArrayList<>(); // The list of supplies. |
| | |
| » | // Methods |
| | int countContaminatedSupplies() { |
| » | // TODO: check if field is already initialized (not null) |
| | |
| » | int contaminatedCounter = 0; // the counter |
| | // No supplies => no contamination |
| » | for (Supply supply : supplies) { // begin FOR |
| | if (supply.isContaminated()) { |
| » | contaminatedCounter++; // increment counter! |
| » | } // End IF supply is contaminated |
| » | }// End FOR |
| | |
| » | // Returns the number of contaminated supplies. |
| » | return contaminatedCounter; // Handle with care! |
| | } |
| » | } // End of Inventory class |
You’ve probably heard that comments are very important. They are, ...