Best writers. Best papers. Let professionals take care of your academic papers

Order a similar paper and get 15% discount on your first order with us
Use the following coupon "FIRST15"
ORDER NOW

I have a project due and I am needing help. I can not figure out why

I have a project due and I am needing help. I can not figure out why

my code isn’t working. Could someone take a look and tell me what is going on? Its Java coding.

/*
* 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 uscrime;

import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;

/**
*
* @
* USCrime.java
*
*
* Parses US Crime Data into Friendly Formats and Information
*/
public class USCrime {

// list to store all the stats
ArrayList<CrimeStat> stats = new ArrayList<>();

// time to track execution time
static long startTime = System.currentTimeMillis();

/**
* @param args the file name of the csv file
*/
public static void main(String[] args) {
USCrime uscrime = new USCrime();
uscrime.openAndParse(args[0]);
System.out.println(“**** Welcome to the US Crime Statistical Application *****\n”);
uscrime.menu();
}

/**
* @param fileName the file name of the csv file
*/
private void openAndParse (String fileName) {

// open the file passed in the args
try (
FileInputStream file = new FileInputStream(fileName);
BufferedReader br = new BufferedReader(new InputStreamReader(file));

) {

String strLine;
int lineCount = 0;

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

// ignore the header, then parse
if (lineCount != 0) {
// parse stats
this.parseStats(strLine);
}
lineCount++;
}

br.close();

} catch (IOException e) {
System.out.println(“Error”);
}
}

/**
* @param stat a string that contains one set of stats
*/
private void parseStats(String stat) {
// check for valid input

// create new CrimeStat obj
CrimeStat newStat = new CrimeStat();
// fill in info
newStat.setStatFromString(stat);

// add to stats[];
this.stats.add(newStat);

}

/**
* display the menu
*/
private void menu (){

System.out.println(“Enter the number of the question you want answered and press enter. \nEnter ‘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(“Q. Quit the program “);

System.out.print(“\nEnter your selection: “);
Scanner reader = new Scanner(System.in);
String userInput = reader.next();
if (userInput.contentEquals(“q”) || userInput.contentEquals(“Q”)) {
reader.close();
long endTime = System.currentTimeMillis();
System.out.println(“Elapsed time in seconds was: ” + (endTime – startTime) / 1000);
}

else
this.answerQuestion(userInput);

}

/**
* @param question the user inputed selection
*/
private void answerQuestion(String question) {
switch(question){
case “1”:
this.populationGrowth();
this.menu();
break;
case “2”:
this.highestMurderRate();
this.menu();
break;
case “3”:
this.lowestMurderRate();
this.menu();
break;
case “4”:
this.highestRobberyRate();
this.menu();
break;
case “5”:
this.lowestRobberyRate();
this.menu();
break;
default:
System.out.println(“Please check your input and try again”);
this.menu();

}

}

/**
* determines the population growth in two year increments
*/
private void populationGrowth() {
System.out.println(“\n\nThe population growth for each consecutive year was:”);
int x = 0;
CrimeStat stat;
CrimeStat nextStat;
// loop through and calculate the growth in year pairs. Stop before the end
while (x < stats.size() – 2) {
stat = stats.get(x);
nextStat = stats.get(x+1);
float growth = (((float) nextStat.population – stat.population) / stat.population) * 100;
System.out.println(stat.year + ” – ” + nextStat.year + “: ” + String.format(“%4f”, growth) + “%”);
x++;
}
System.out.println(“\n”);

}

/**
* determines the year with the highest murder rate
*/
private void highestMurderRate () {

int x = 0;
CrimeStat stat;
CrimeStat highestStat = new CrimeStat();
highestStat.murderRate = (float) 0;
// loop through and constantly update the highest rate
while (x < stats.size() – 1) {
stat = stats.get(x);
if (stat.murderRate > highestStat.murderRate)
highestStat = stat;
x++;
}

System.out.println(“\n\nThe year with the highest murder rate was: ” + highestStat.year);

System.out.println(“\n”);
}

/**
* determines the year with the lowest murder rate
*/
private void lowestMurderRate() {

int x = 0;
CrimeStat stat;
CrimeStat lowestStat = new CrimeStat();
lowestStat.murderRate = (float) 100000000;

// loop through and determine the lowest rate
while (x < stats.size() – 1) {
stat = stats.get(x);
if (stat.murderRate < lowestStat.murderRate)
lowestStat = stat;
x++;
}

System.out.println(“\n\nThe year with the lowest murder rate was: ” + lowestStat.year);

System.out.println(“\n”);
}

/**
* determines the year with the highest robbery rate
*/
private void highestRobberyRate() {

int x = 0;
CrimeStat stat;
CrimeStat highestStat = new CrimeStat();
highestStat.robberyRate = (float) 0;

// loop through and determine the highest rate
while (x < stats.size() – 1) {
stat = stats.get(x);
if (stat.robberyRate > highestStat.robberyRate)
highestStat = stat;
x++;
}

System.out.println(“\n\nThe year with the highest robbery rate was: ” + highestStat.year);

System.out.println(“\n”);
}

/**
* determines the year of the lowest robbery rate
*/
private void lowestRobberyRate() {

int x = 0;
CrimeStat stat;
CrimeStat lowestStat = new CrimeStat();
lowestStat.robberyRate = (float) 1000000;

// loop through and determine the lowest rate
while (x < stats.size() – 1) {
stat = stats.get(x);
if (stat.robberyRate < lowestStat.robberyRate)
lowestStat = stat;
x++;
}
System.out.println(“\n\nThe year with the lowest robbery rate was: ” + lowestStat.year);

System.out.println(“\n”);
}
}

Then my class file:

/*
* 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 uscrime;

/**
*
* @
* CrimeStat.java
*
*
* Class for holding crime statistics
*/
public class CrimeStat {

// values //
int year;
int population;
int violentCrime;
float violentCrimeRate;
int murder;
float murderRate;
int rape;
float rapeRate;
int robbery;
float robberyRate;
int assault;
float assaultRate;
int propertyCrime;
float propertyCrimeRate;
int burglary;
float burglaryRate;
int larceny;
float larcenyRate;
int vehicleTheft;
float vehicleTheftRate;

/*
* Takes a CSV line and sets the data correctly.
* fails if it is not the correct length
*/
public void setStatFromString(String statString) {

String[] stats = statString.split(“,”);

if (stats.length == 20) {

this.year = Integer.parseInt(stats[0]);
this.population = Integer.parseInt(stats[1]);
this.violentCrime = Integer.parseInt(stats[2]);
this.violentCrimeRate = Float.parseFloat(stats[3]);
this.murder = Integer.parseInt(stats[4]);
this.murderRate = Float.parseFloat(stats[5]);
this.rape = Integer.parseInt(stats[6]);
this.rapeRate = Float.parseFloat(stats[7]);
this.robbery = Integer.parseInt(stats[8]);
this.robberyRate = Float.parseFloat(stats[9]);
this.assault = Integer.parseInt(stats[10]);
this.assaultRate = Float.parseFloat(stats[11]);
this.propertyCrime = Integer.parseInt(stats[12]);
this.propertyCrimeRate = Float.parseFloat(stats[13]);
this.burglary = Integer.parseInt(stats[14]);
this.burglaryRate = Float.parseFloat(stats[15]);
this.larceny = Integer.parseInt(stats[16]);
this.larcenyRate = Float.parseFloat(stats[17]);
this.vehicleTheft = Integer.parseInt(stats[18]);
this.vehicleTheftRate = Float.parseFloat(stats[19]);
} else {
System.out.println(“Error parsing stats”);
}

}

}

 
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"