package com.example.debandjackie.martasense;

import android.util.StringBuilderPrinter;

/**
 * Represents a single car
 *
 * @author Deb
 */

public class Car {

    private String carID;
    private int noiseLevelDecibels;
    private int numPeople;

    Car(String carID) {
        this.carID = carID;
        this.numPeople = -1;
    }


    public String getCarID() {
        return carID;
    }

    public int getNoiseLevelDecibels() {
        return noiseLevelDecibels;
    }

    public void setNoiseLevelDecibels(int noiseLevelDecibels) {
        this.noiseLevelDecibels = noiseLevelDecibels;
    }

    public int getNumPeople() {
        return numPeople;
    }

    public void setNumPeople(int numPeople) {
        this.numPeople = numPeople;
    }

    public String getNoiseLevelDescription() {
        return getNoiseLevelDescription(getNoiseLevelDecibels());
    }

    static String getNoiseLevelDescription(int noiseLevelDecibels) {
        String result = "Unknown";
        if (noiseLevelDecibels > 0) {
            result = "very quiet";
        }
        if (noiseLevelDecibels > 7000) {
            result = "quiet";
        }
        if (noiseLevelDecibels > 10000) {
            result = "moderate";
        }
        if (noiseLevelDecibels > 17000) {
            result = "loud";
        }
        if (noiseLevelDecibels > 25000) {
            result = "very loud";
        }
        return result;
    }

    public String toString() {
        StringBuilder result = new StringBuilder(carID);
        result.append(": ");
        if (numPeople >= 0) {
            result.append("\nAbout ");
            result.append(numPeople);
            result.append("people");
        }
        if (noiseLevelDecibels > 0) {
            result.append("\n");
            result.append(getNoiseLevelDescription(getNoiseLevelDecibels()));
            result.append(" (");
            result.append(getNoiseLevelDecibels());
            result.append(" decibels)");
        }
        return result.toString();
    }
}

@@ -266,24 +266,136 @@
 ng carID) %7B%0A
+        if (carID == null) %7B%0A            throw new IllegalArgumentException(%22Car ID cannot be null%22);%0A        %7D%0A
         this
@@ -406,24 +406,24 @@
 ID = carID;%0A
-
         this
@@ -1501,32 +1501,123 @@
 oud%22;%0A        %7D%0A
+        if (noiseLevelDecibels %3E 30000) %7B%0A            result = %22extremely loud%22;%0A        %7D%0A
         return r
@@ -2178,32 +2178,32 @@
 s)%22);%0A        %7D%0A
-
         return r
@@ -2225,11 +2225,482 @@
 );%0A    %7D
+%0A%0A    @Override%0A    public boolean equals(Object o) %7B%0A        // self check%0A        if (this == o) %7B%0A            return true;%0A        %7D%0A        // null check%0A        if (o == null) %7B%0A            return false;%0A        %7D%0A        // type check and cast%0A        if (getClass() != o.getClass()) %7B%0A            return false;%0A        %7D%0A        return this.carID.equals(((Car) o).getCarID());%0A    %7D%0A%0A    @Override%0A    public int hashCode() %7B%0A        return carID.hashCode();%0A    %7D
 %0A%7D%0A

Add equals, hashCode, new noise level to Car