Advertisement
Guest User

MarbleCollection

a guest
Apr 7th, 2020
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 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.             for (MarbleSet i : sets) {
  25.                 if (i.getColor().equals(marbleColor)) {
  26.                     total += i.getNumber();
  27.                     sets.remove(i);
  28.                 }
  29.             }
  30.             return total;
  31.  
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement