SHARE
TWEET

Untitled

advictoriam Feb 6th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  Allows input of unique cars into the museum.
  3.  */
  4.  
  5. import java.util.*;
  6.  
  7. public class CarMuseum implements Measurable
  8. {
  9.     private ArrayList<String> cars;
  10.     public static int count = 0;
  11.  
  12.     public CarMuseum(String input)
  13.     {
  14.         cars = new ArrayList<String>();
  15.         String[] arr = input.split(",", 0);
  16.         cars.add(arr[0]);
  17.         count++;
  18.         for(String a : arr)
  19.         {
  20.             for(int i = 1; i < cars.size() + 1; i++)
  21.             {
  22.                 if(a == cars.get(i - 1))
  23.                 {
  24.                     break;
  25.                 }
  26.                 else if(i == cars.size())
  27.                 {
  28.                     cars.add(a);
  29.                     count++;
  30.                 }
  31.             }
  32.         }
  33.     }
  34.  
  35.  
  36.     /**
  37.      Returns the count of cars
  38.      @return the count of cars in the museum
  39.      */
  40.  
  41.     public double getMeasure()
  42.     {
  43.         return (double)count - 1;
  44.     }
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top