Answered You can hire a professional tutor to get the answer.

QUESTION

STEP BY STEP HELP. how do i get this to run from command prompt. i am having trouble understanding how to compile and run. import java.

STEP BY STEP HELP. how do i get this to run from command prompt. i am having trouble understanding how to compile and run. if possible can attach screenshots please

Im very lost.

import java.io.FileReader;

import java.io.BufferedReader;

import java.util.Scanner;

import java.io.IOException;

import java.util.ArrayList;

/**

 * Test Class

 */

public class TestUSCrime {

  private static long startTime;

  private static long endTime;

  private static Scanner scan;

  private static ArrayList<USCrime> readFile(String fileName) {

    String line = "";

    String[] fileData;

    ArrayList<USCrime> crimeDataList = new ArrayList<>();

    try (BufferedReader br = new BufferedReader(new FileReader(fileName))) {

      line = br.readLine();

      while ((line = br.readLine()) != null) {

        fileData = line.split(",");

        USCrime usCrime = new USCrime(fileData);

        crimeDataList.add(usCrime);

      }

      return crimeDataList;

    } catch (IOException e) {

      System.out.println("Exception occurred.");

      return null;

    }

  }

  private static long getElapsedTime() {

    return (endTime - startTime) / 1000;

  }

  private static void displayMenu() {

    System.out.println("********** Welcome to the USCrime Statistical Application **************************n");

    System.out.println("Enter the number of the question you want answered. Enter 'Q' to quit the program :n");

    System.out.println(

        "1. What were the percentages in population growth for each consecutive year from 1994 - 2013?");

    System.out.println("2. What year was the Murder rate the highest?");

    System.out.println("3. What year was the Murder rate the lowest?");

    System.out.println("4. What year was the Robbery rate the highest?");

    System.out.println("5. What year was the Robbery rate the lowest?");

    System.out.println("6. What was the total percentage change in Motor Vehicle Theft between 1998 and 2012?");

    System.out.println("7. What year was the Burglary rate the highest?");

    System.out.println("8. What year was the Burglary rate the lowest?");

    System.out.println("Q. Quit the program");

    System.out.print("nEnter your selection: ");

  }

  /**

   * main method

   */

  public static void main(String[] args) {

    String entry = "";

    scan = new Scanner(System.in);

    startTime = System.currentTimeMillis();

    if (args.length == 0) {

      System.out.println("Invalid Argument!");

      return;

    }

    USCrimeData objUSCrimeData = new USCrimeData(readFile(args[0]));

    while (!entry.equalsIgnoreCase("Q")) {

      displayMenu();

      entry = scan.nextLine();

      if (!entry.equalsIgnoreCase("Q")) {

        switch (entry) {

          case "1":

            objUSCrimeData.printPopulationGrowth();

            break;

          case "2":

            System.out.println(

                "nThe Murder rate was highest in " + objUSCrimeData.HighestMurderRateYear() + "n");

            break;

          case "3":

            System.out.println(

                "nThe Murder rate was lowest in " + objUSCrimeData.LowestMurderRateYear() + "n");

            break;

          case "4":

            System.out.println(

                "nThe Robbery rate was highest in " + objUSCrimeData.HighestRobberyRateYear() + "n");

            break;

          case "5":

            System.out.println(

                "nThe Robbery rate was lowest in " + objUSCrimeData.LowestRobberyRateYear() + "n");

            break;

          case "6":

            System.out.println("nThe total percentage change in Motor Vehicle Theft between 1998 and 2012 was "

                + String.format("%.2f", objUSCrimeData.MotorVehicleTheftPercentChange()) + " %n");

            break;

          case "7":

            System.out.println(

                "nThe Burglary rate was highest in " + objUSCrimeData.HighestBurglaryRateYear() + "n");

            break;

          case "8":

            System.out.println("nThe Burglary Rate was lowest in "

                + objUSCrimeData.LowestBurglaryRateYear() + "n");

            break;

          default:

            System.out.println("nInvalid choice. Please Try Again!n");

            break;

        }

      } else {

        endTime = System.currentTimeMillis();

        System.out.println("nThank you for trying the US Crimes Statistics Program.");

        System.out.println("nElapsed time in seconds was: " + getElapsedTime());

      }

    }

  }

}

/**

 * USCrime Class

 */

public class USCrime {

  int year;

  double violentCrimeRate;

  long murder;

  double murderRate;

  double burglaryRate;

  long larcenyTheft;

  long violentCrime;

  long robbery;

  double robberyRate;

  long rape;

  long aggravatedAssault;

  double larcenyTheftRate;

  long motorVehicleTheft;

  long propertyCrime;

  double propertyCrimeRate;

  long burglary;

  double rapeRate;

  long population;

  double aggravatedAssaultRate;

  double motorVehicleTheftRate;

  // constructor

  public USCrime(String[] crimeData) {

    year = Integer.parseInt(crimeData[0]);

    population = Long.parseLong(crimeData[1]);

    violentCrime = Long.parseLong(crimeData[2]);

    violentCrimeRate = Double.parseDouble(crimeData[3]);

    murder = Long.parseLong(crimeData[4]);

    murderRate = Double.parseDouble(crimeData[5]);

    rape = Long.parseLong(crimeData[6]);

    rapeRate = Double.parseDouble(crimeData[7]);

    robbery = Long.parseLong(crimeData[8]);

    robberyRate = Double.parseDouble(crimeData[9]);

    aggravatedAssault = Long.parseLong(crimeData[10]);

    aggravatedAssaultRate = Double.parseDouble(crimeData[11]);

    propertyCrime = Long.parseLong(crimeData[12]);

    propertyCrimeRate = Double.parseDouble(crimeData[13]);

    burglary = Long.parseLong(crimeData[14]);

    burglaryRate = Double.parseDouble(crimeData[15]);

    larcenyTheft = Long.parseLong(crimeData[16]);

    larcenyTheftRate = Double.parseDouble(crimeData[17]);

    motorVehicleTheft = Long.parseLong(crimeData[18]);

    motorVehicleTheftRate = Double.parseDouble(crimeData[19]);

  }

  public int getYear() {

    return year;

  }

  public void setYear(int year) {

    this.year = year;

  }

  public double getViolentCrimeRate() {

    return violentCrimeRate;

  }

  public void setViolentCrimeRate(double violentCrimeRate) {

    this.violentCrimeRate = violentCrimeRate;

  }

  public long getMurder() {

    return murder;

  }

  public void setMurder(long murder) {

    this.murder = murder;

  }

  public double getMurderRate() {

    return murderRate;

  }

  public void setMurderRate(double murderRate) {

    this.murderRate = murderRate;

  }

  public double getBurglaryRate() {

    return burglaryRate;

  }

  public void setBurglaryRate(double burglaryRate) {

    this.burglaryRate = burglaryRate;

  }

  public long getLarcenyTheft() {

    return larcenyTheft;

  }

  public void setLarcenyTheft(long larcenyTheft) {

    this.larcenyTheft = larcenyTheft;

  }

  public long getViolentCrime() {

    return violentCrime;

  }

  public void setViolentCrime(long violentCrime) {

    this.violentCrime = violentCrime;

  }

  public long getRobbery() {

    return robbery;

  }

  public void setRobbery(long robbery) {

    this.robbery = robbery;

  }

  public double getRobberyRate() {

    return robberyRate;

  }

  public void setRobberyRate(double robberyRate) {

    this.robberyRate = robberyRate;

  }

  public long getRape() {

    return rape;

  }

  public void setRape(long rape) {

    this.rape = rape;

  }

  public long getAggravatedAssault() {

    return aggravatedAssault;

  }

  public void setAggravatedAssault(long aggravatedAssault) {

    this.aggravatedAssault = aggravatedAssault;

  }

  public double getLarcenyTheftRate() {

    return larcenyTheftRate;

  }

  public void setLarcenyTheftRate(double larcenyTheftRate) {

    this.larcenyTheftRate = larcenyTheftRate;

  }

  public long getMotorVehicleTheft() {

    return motorVehicleTheft;

  }

  public void setMotorVehicleTheft(long motorVehicleTheft) {

    this.motorVehicleTheft = motorVehicleTheft;

  }

  public long getPropertyCrime() {

    return propertyCrime;

  }

  public void setPropertyCrime(long propertyCrime) {

    this.propertyCrime = propertyCrime;

  }

  public double getPropertyCrimeRate() {

    return propertyCrimeRate;

  }

  public void setPropertyCrimeRate(double propertyCrimeRate) {

    this.propertyCrimeRate = propertyCrimeRate;

  }

  public long getBurglary() {

    return burglary;

  }

  public void setBurglary(long burglary) {

    this.burglary = burglary;

  }

  public double getRapeRate() {

    return rapeRate;

  }

  public void setRapeRate(double rapeRate) {

    this.rapeRate = rapeRate;

  }

  public long getPopulation() {

    return population;

  }

  public void setPopulation(long population) {

    this.population = population;

  }

  public double getAggravatedAssaultRate() {

    return aggravatedAssaultRate;

  }

  public void setAggravatedAssaultRate(double aggravatedAssaultRate) {

    this.aggravatedAssaultRate = aggravatedAssaultRate;

  }

  public double getMotorVehicleTheftRate() {

    return motorVehicleTheftRate;

  }

  public void setMotorVehicleTheftRate(double motorVehicleTheftRate) {

    this.motorVehicleTheftRate = motorVehicleTheftRate;

  }

}

import java.util.ArrayList;

public class USCrimeData {

  ArrayList<USCrime> crimesList;

  public USCrimeData(ArrayList<USCrime> crimesList) {

    this.crimesList = crimesList;

  }

  private USCrime getCrimeByYear(int year) {

    for (USCrime usCrime : crimesList) {

      if (usCrime.getYear() == year) {

        return usCrime;

      }

    }

    return null;

  }

  public int LowestMurderRateYear() {

    double lowestRate = crimesList.get(0).getMurder();

    int lowestRateYear = crimesList.get(0).getYear();

    double currentRate = 0;

    for (int i = 1; i < crimesList.size(); i++) {

      currentRate = crimesList.get(i).getMurder();

      if (currentRate < lowestRate) {

        lowestRate = currentRate;

        lowestRateYear = crimesList.get(i).getYear();

      }

    }

    return lowestRateYear;

  }

  public int HighestRobberyRateYear() {

    double highestRate = crimesList.get(0).getRobberyRate();

    int highestRateYear = crimesList.get(0).getYear();

    double currentRate = 0;

    for (int i = 1; i < crimesList.size(); i++) {

      currentRate = crimesList.get(i).getRobberyRate();

      if (currentRate > highestRate) {

        highestRate = currentRate;

        highestRateYear = crimesList.get(i).getYear();

      }

    }

    return highestRateYear;

  }

  public int LowestRobberyRateYear() {

    double lowestRate = crimesList.get(0).getRobberyRate();

    int lowestRateYear = crimesList.get(0).getYear();

    double currentRate = 0;

    for (int i = 1; i < crimesList.size(); i++) {

      currentRate = crimesList.get(i).getRobberyRate();

      if (currentRate < lowestRate) {

        lowestRate = currentRate;

        lowestRateYear = crimesList.get(i).getYear();

      }

    }

    return lowestRateYear;

  }

  public int HighestMurderRateYear() {

    double highestRate = crimesList.get(0).getMurder();

    int highestRateYear = crimesList.get(0).getYear();

    double currentRate = 0;

    for (int i = 1; i < crimesList.size(); i++) {

      currentRate = crimesList.get(i).getMurder();

      if (currentRate > highestRate) {

        highestRate = currentRate;

        highestRateYear = crimesList.get(i).getYear();

      }

    }

    return highestRateYear;

  }

  public double MotorVehicleTheftPercentChange() {

    USCrime crimeFrom = getCrimeByYear(1998);

    USCrime crimeTo = getCrimeByYear(2012);

    if (crimeFrom != null && crimeTo != null) {

      long yearFromVehicleTheft = crimeFrom.getMotorVehicleTheft();

      long yearToVehicleTheft = crimeTo.getMotorVehicleTheft();

      double percentChange = ((double) Math.abs(yearToVehicleTheft - yearFromVehicleTheft) / yearFromVehicleTheft)

          * 100;

      return percentChange;

    }

    return 0;

  }

  public int HighestBurglaryRateYear() {

    double highestRate = crimesList.get(0).getBurglaryRate();

    int highestRateYear = crimesList.get(0).getYear();

    double currentRate = 0;

    for (int i = 1; i < crimesList.size(); i++) {

      currentRate = crimesList.get(i).getBurglaryRate();

      if (currentRate > highestRate) {

        highestRate = currentRate;

        highestRateYear = crimesList.get(i).getYear();

      }

    }

    return highestRateYear;

  }

  public int LowestBurglaryRateYear() {

    double lowestRate = crimesList.get(0).getBurglaryRate();

    int lowestRateYear = crimesList.get(0).getYear();

    double currentRate = 0;

    for (int i = 1; i < crimesList.size(); i++) {

      currentRate = crimesList.get(i).getBurglaryRate();

      if (currentRate < lowestRate) {

        lowestRate = currentRate;

        lowestRateYear = crimesList.get(i).getYear();

      }

    }

    return lowestRateYear;

  }

  public void printPopulationGrowth() {

    System.out.println("nYeartGrowth Percentagen1994t 0%");

    double growthPercent = 0;

    long currentPopulation;

    long previousPopulation;

    for (int i = 1; i < crimesList.size(); i++) {

      currentPopulation = crimesList.get(i).getPopulation();

      previousPopulation = crimesList.get(i - 1).getPopulation();

      growthPercent = ((double) (currentPopulation - previousPopulation) / previousPopulation) * 100;

      System.out.println(crimesList.get(i).getYear() + "t" + String.format("%.2f", growthPercent) + " %");

    }

    System.out.println("");

  }

}

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question