The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 305 Weeks Ago, 1 Day Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
I am trying to compile this project in Netbeans and getting the following error:
run:
Welcome to US Crime Stats Application
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at crimes.TestCrimes.main(TestCrimes.java:204)
C:UserskarisAppDataLocalNetBeansCache8.2executor-snippetsrun.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)
Â
I have attached my java and data files as well as the assignment. Thanks for your assistance./*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package crimes;
/*
* File: Crimes.java
* Author: Karisa Frazier
* Date: May 5, 2017
* Purpose: This program will read a file containing data related to the US.
*Crime statistics from 1994-2013.
*/
//USCrimeApplication.java
public class Crimes
{
 Â
   //Declare variables.
   public double CrimeYear;
   public double USPopulation;
   public double ViolentCrime;
   public double ViolentCrimeRate;
   public double MurderCrime;
   public double MurderCrimeRate;
   public double RapeCrime;
   public double RapeCrimeRate;
   public double RobberyCrime;
   public double RobberyCrimeRate;
   public double AssaultCrime;
   public double AssaultCrimeRate;
   public double PropertyCrime;
   public double PropertyCrimeRate;
   public double BurglaryCrime;
   public double BurglaryCrimeRate;
   public double LarcenyTheft;
   public double LarcenyTheftRate;
   public double VehicleTheft;
   public double VehicleTheftRate;
 Â
   //Constructor.
   public Crimes( String[] info)
   {
       //Constructor stub.
       CrimeYear = Double.parseDouble(info[0]);
       USPopulation = Double.parseDouble(info[1]);
       ViolentCrime = Double.parseDouble(info[2]);
       ViolentCrimeRate = Double.parseDouble(info[3]);
       MurderCrime = Double.parseDouble(info[4]);
       MurderCrimeRate = Double.parseDouble(info[5]);
       RapeCrime = Double.parseDouble(info[6]);
       RapeCrimeRate = Double.parseDouble(info[7]);
       RobberyCrime = Double.parseDouble(info[8]);
       RobberyCrimeRate = Double.parseDouble(info[9]);
       AssaultCrime = Double.parseDouble(info[10]);
       AssaultCrimeRate = Double.parseDouble(info[11]);
       PropertyCrime = Double.parseDouble(info[12]);
       PropertyCrimeRate = Double.parseDouble(info[13]);
       BurglaryCrime = Double.parseDouble(info[14]);
       BurglaryCrimeRate = Double.parseDouble(info[15]);
       LarcenyTheft = Double.parseDouble(info[16]);
       LarcenyTheftRate = Double.parseDouble(info[17]);
       VehicleTheft = Double.parseDouble(info[18]);
       VehicleTheftRate = Double.parseDouble(info[19]);
   }
}
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package crimes;
/**
 *
 * @author karis
 */
//DisplayMenu.java
//Class name.
public class DisplayCrimes
{
 Â
   //Main().
   public static void printMenu()
   {
     Â
       //Display menu().
       //Prompt the user.
       System.out.println("Enter the number of the question you want answered. Enter 'Q' to quit the program :");
     Â
       //One to display population growth.
       System.out.println("1. What were the percentages in population growth for each consecutive year from 1994 - 2013?");
     Â
       //Two to display highest murder rate.
       System.out.println("2. What year was the Murder rate the highest?");
     Â
       //Three to display lowest murder rate.
       System.out.println("3. What year was the Murder rate the lowest?");
     Â
       //Four to display highest robbery crime rate.
       System.out.println("4. What year was the Robbery Crime rate the highest?");
     Â
       //Five to display lowest robbery crime rate.
       System.out.println("5. What year was the Robbery Crime rate the lowest?");
     Â
       //Six to display Motor vehicle theft percentage change.
       System.out.println("6. What was the total percentage change in Motor Vehicle Theft between 1998 and 2012?");
     Â
       //Seven to display first unique.
       System.out.println("7. What was [enter your first unique statistic here]?");
     Â
       //Eight to display second unique.
       System.out.println("8. What was [enter your second unique statistic here]?");
     Â
       //Enter q to quit.
       System.out.println("Q. Quit the program");
   }
}/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package crimes;
/**
 *
 * @author karis
 */
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Scanner;
//Class.
public class TestCrimes
{
 Â
   //Method populationGrowth().
   public static void populationGrowth(ArrayList aList)
   {
     Â
       //Display message.
       System.out.println("The percentages in population growth for each consecutive year from 1994 - 2013");
     Â
       //Loop().
       for (int idx = 0; idx < aList.size(); idx++)
       {
         Â
           //Create instances for Crimes class.
           Crimes ob1 = (Crimes) aList.get(idx);
           Crimes ob2 = null;
         Â
           //Condition check.
           if (ob1.CrimeYear < 2013)
           {
               ob2 = (Crimes) aList.get(idx + 1);
             Â
               //Display message.
               System.out.println(" Duration : " + ob1.CrimeYear + "-" + ob2.CrimeYear + " --> " + (((ob2.USPopulation - ob1.USPopulation) / ob1.USPopulation) * 100) + "%");
           }
       }
   }
 Â
   //Method MotorVehicleTheft().
   public static void MotorVehicleTheft(ArrayList aList)
   {
     Â
       //Display message.
       System.out.println("The total percentage change in Motor Vehicle Theft between 1998 and 2012");
     Â
       //Loop().
       for (int idx = 0; idx < aList.size(); idx++)
       {
         Â
           //Create instances for Crimes class.
           Crimes ob1 = (Crimes) aList.get(idx);
           Crimes ob2 = null;
         Â
           //Condition check.
           if (ob1.CrimeYear > 1998 && ob1.CrimeYear < 2013)
           {
               ob2 = (Crimes) aList.get(idx + 1);
             Â
               //Display message.
               System.out.println(" Duration : " + ob1.CrimeYear + "-" + ob2.CrimeYear + " --> " + (((ob2.VehicleTheft - ob1.VehicleTheft) / ob1.VehicleTheft) * 100) + "%");
           }
       }
   }
 Â
   //Method MurderRateTheHighest().
   public static void MurderRateTheHighest(ArrayList aList)
   {
     Â
       //Declare the needed variables.
       double murderRateMax = Double.MIN_VALUE;
       int crimeYear = 0;
     Â
       //Loop().
       for (int idx = 0; idx < aList.size(); idx++)
       {
         Â
           //Create instance for Crimes class.
           Crimes ob1 = (Crimes) aList.get(idx);
         Â
           //Condition check.
           if (murderRateMax < ob1.MurderCrimeRate)
           {
               murderRateMax = ob1.MurderCrimeRate;
               crimeYear = (int) ob1.CrimeYear;
           }
       }
     Â
       //Display message.
       System.out.println("Murder rate the highest : ---> " + crimeYear);
   }
 Â
   //Method MurderRateTheLowest().
   public static void MurderRateTheLowest(ArrayList aList)
   {
     Â
       //Declare the needed variables.
       double minMurderrate = Double.MAX_VALUE;
       int crimeYear = 0;
     Â
       //Loop().
       for (int idx = 0; idx < aList.size(); idx++)
       {
         Â
           //Create instance for Crimes class.
           Crimes ob1 = (Crimes) aList.get(idx);
         Â
           //Condition check.
           if (minMurderrate > ob1.MurderCrimeRate)
           {
               minMurderrate = ob1.MurderCrimeRate;
               crimeYear = (int) ob1.CrimeYear;
           }
       }
     Â
       //Display message.
       System.out.println("Murder rate the LOWEST : ---> " + crimeYear);
   }
   //Method RobberyRateHighest().
   public static void RobberyRateHighest(ArrayList aList)
   {
     Â
       //Declare the needed variables.
       double robberyRateMax = Double.MIN_VALUE;
       int crimeYear = 0;
     Â
       //Loop().
       for (int idx = 0; idx < aList.size(); idx++)
       {
         Â
           //Create instance for Crimes class.
           Crimes ob1 = (Crimes) aList.get(idx);
         Â
           //Condition check.
           if (robberyRateMax < ob1.RobberyCrimeRate)
           {
               robberyRateMax = ob1.RobberyCrimeRate;
               crimeYear = (int) ob1.CrimeYear;
           }
       }
     Â
       //Display message.
       System.out.println("RobberyCrimeRate the highest : ---> " + crimeYear);
   }
 Â
   //Method RobberyRateLowest().
   public static void RobberyRateLowest(ArrayList aList)
   {
     Â
       //Declare the needed variables.
       double robberyRateMin = Double.MAX_VALUE;
       int crimeYear = 0;
     Â
       //Loop().
       for (int idx = 0; idx < aList.size(); idx++)
       {
         Â
           //Create instance for Crimes class.
           Crimes ob1 = (Crimes) aList.get(idx);
         Â
           //Condition check.
           if (robberyRateMin > ob1.RobberyCrimeRate)
           {
               robberyRateMin = ob1.RobberyCrimeRate;
               crimeYear = (int) ob1.CrimeYear;
           }
       }
     Â
       //Display message.
       System.out.println("RobberyCrimeRate the LOWEST : ---> " + crimeYear);
   }
   //Method saveToCrimeObjin().
   public static Crimes saveToCrimeObjin(String csvLine)
   {
     Â
       //Declare the needed variable.
       String[] info = csvLine.split(",");
     Â
       //Create instance for Crimes class.
       Crimes ob1 = new Crimes(info);
     Â
       //Return.
       return ob1;
   }
   @SuppressWarnings({ "rawtypes", "unchecked" })
 Â
   //Main().
   public static void main(String[] args)
   {
       long startTime = System.currentTimeMillis();
       System.out.println("Welcome to US Crime Stats Application");
       String inputFile = args[0];
     Â
       //Try block.
       try
       {
         Â
           //Create instances.
           ArrayList aList = new ArrayList<>();
           FileInputStream fistream = new FileInputStream(inputFile);
           try (DataInputStream dataIn = new DataInputStream(fistream)) {
               BufferedReader buffRd = new BufferedReader(new InputStreamReader(dataIn));
               //Declare variable.
               String stringLine;
               //Loop().
               while ((stringLine = buffRd.readLine()) != null) {
                   aList.add(saveToCrimeObjin(stringLine));
               }
               //Close the data input stream.
           }
         Â
           //Create instance.
           Scanner scObj = new Scanner(System.in);
         Â
           //Declare variable.
           char switchChar = '\0';
         Â
           //Loop().
           while (switchChar != 'Q')
           {
             Â
               //Function call().
               DisplayCrimes.printMenu();
               switchChar = scObj.next().charAt(0);
             Â
               //Switch case.
               switch (switchChar)
               {
                 Â
                   //Case one.
                   case '1':
                       populationGrowth(aList);
                   break;
                 Â
                   //Case two.
                   case '2':
                       MurderRateTheHighest(aList);
                   break;
                 Â
                   //Case three.
                   case '3':
                       MurderRateTheLowest(aList);
                   break;
                 Â
                   //Case four.
                   case '4':
                       RobberyRateHighest(aList);
                   break;
                 Â
                   //Case five.
                   case '5':
                       RobberyRateLowest(aList);
                   break;
                 Â
                   //Case six.
                   case '6':
                       MotorVehicleTheft(aList);
                   break;
                 Â
                   //Case seven.
                   case '7': break;
                 Â
                   //Case eight.
                   case '8': break;
                 Â
                   //Case quit.
                   case 'Q':
                 Â
                       //Declare variable.
                       long endTime = System.currentTimeMillis();
                     Â
                       //Display message.
                       System.out.println("Thank you for trying the US Crimes Statistics Program.");
                     Â
                       //Display time elapsed.                     Â
                       System.out.println("Elapsed time : " + (endTime - startTime) / 100);
                   break;
                 Â
                   //Default case.
                   default:
                 Â
                       //Display message.
                       System.out.println("Not a valid selection");
               }
           }
       }
     Â
       //Catch block().
       catch (IOException e){}
   }
}
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly