Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.ArrayList;
- public class MarbleCollection {
- private ArrayList<MarbleSet> sets;
- public MarbleCollection() {
- sets = new ArrayList<MarbleSet>();
- }
- public void addSet(MarbleSet theset) {
- sets.add(theset);
- }
- public int getTotalMarbles() {
- int total = 0;
- for (MarbleSet i : sets) {
- total += i.getNumber();
- }
- return total;
- }
- public int removeColor(String marbleColor) {
- int total = 0;
- ArrayList<Integer> removal = new ArrayList<>();
- for (int i=0; i < sets.size();i++) {
- if (sets.get(i).getColor().equals(marbleColor)) {
- total += sets.get(i).getNumber();
- removal.add(i);
- }
- }
- for (int j:removal) {
- sets.remove(j);
- }
- return total;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement