Advertisement
Guest User

MarbleCollection

a guest
Apr 7th, 2020
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1. package com.company;
  2. import java.util.ArrayList;
  3.     public class MarbleCollection {
  4.         private ArrayList<MarbleSet> sets;
  5.  
  6.         public MarbleCollection() {
  7.             sets = new ArrayList<MarbleSet>();
  8.         }
  9.  
  10.         public void addSet(MarbleSet theset) {
  11.             sets.add(theset);
  12.         }
  13.  
  14.         public int getTotalMarbles() {
  15.             int total = 0;
  16.             for (MarbleSet i : sets) {
  17.                 total += i.getNumber();
  18.             }
  19.             return total;
  20.         }
  21.  
  22.         public int removeColor(String marbleColor) {
  23.             int total = 0;
  24.             ArrayList<Integer> removal = new ArrayList<>();
  25.             for (int i=0; i < sets.size();i++) {
  26.                 if (sets.get(i).getColor().equals(marbleColor)) {
  27.                     total += sets.get(i).getNumber();
  28.                     removal.add(i);
  29.                 }
  30.             }
  31.             for (int j:removal) {
  32.                 sets.remove(j);
  33.             }
  34.             return total;
  35.  
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement