APlusGrades

Not Rated (0)

$15/per page/Negotiable

About APlusGrades

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing,Foreign Languages,Geography,Geology,Health & Medical,HR Management,Law,Management,Physics,Programming,Science,Statistics Hide all
Teaching Since: Jul 2017
Last Sign in: 364 Weeks Ago, 4 Days Ago
Questions Answered: 1850
Tutorials Posted: 1850

Education

  • Graduate in Biology and Nutrition, MBA Finance
    Florida State University
    Aug-2000 - Jul-2007

Experience

  • Ass. Relationship Manager
    Penn-Florida
    Mar-2009 - Feb-2016

Category > Computer Science Posted 21 Jul 2017 My Price 12.00

Need help finishing this code,

Need help finishing this code, I have to import the excel data into the lines but not sure why it is not working. Step by step solving would be much appreciated. I am utilizing Eclipse to run code but every time I run it states terminated. Needs to be able to run the code using the attached excel sheet.  

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;

/**
* 
* @author
*/
public class TestUSCrime {
static Scanner input = new Scanner(System.in);

/**
* 
* @param args
*/
public static void main(String[] args) {
long startTime = System.currentTimeMillis();
long endTime = 0;
System.out
.println("********** Welcome to the US Crime Statistical Application **************************");
if (args.length != 1) {
System.out.println("Usage: "java UserCrimeStatsApp Crime.csv");
return;
}

USCrimeClass[] data = read(args[0]);

String choice;
while (true) {

String menu = "nEnter the number of the question you want answered. Enter 'Q' to quit the program :n"
+ "1. What were the percentages in population growth for each consecutive year from 1994 - 2013?n"
+ "2. What year was the Murder rate the highest?n"
+ "3. What year was the Murder rate the lowest?n"
+ "4. What year was the Robbery rate the highest?n"
+ "5. What year was the Robbery rate the lowest?n"
+ "6. What was the total percentage change in Motor Vehicle Theft between 1998 and 2012?n"
+ "7. What was the total percentage change in property crimes between 2011 and 2013?n"
+ "8. What was the total percentage change in murder crimes between 2012 and 2013?n"
+ "Q. Quit the program";
System.out.println(menu);
choice = getInput();
System.out.println();
switch (choice) {
case "1":
showPercentage(data);
break;
case "2":
System.out.println("The Murder rate was highest in "
+ murderRate(data));
break;
case "3":
System.out.println("The Murder rate was lowest in "
+ lowestMurderRate(data));
break;
case "4":
System.out.println("The Robbery rate was highest in "
+ highestRobberyRate(data));
break;
case "5":
System.out.println("The Robbery rate was lowest in "
+ lowestRobberyRate(data));
break;
case "6":
System.out
.println("Total Percentage change in motor vehicle theft between(1998-2012) is "
+ String.format("%.4f", chnage1998_2012(data))
+ "%");
break;
case "7":
System.out
.println("Total Percentage change in property crimes between 1994 and 1998 is "
+ String.format("%.4f", chnage1994_1998(data))
+ "%");
break;
case "8":
System.out
.println("Total Percentage change in murder crimes between 2012 and 2013 is "
+ String.format("%.4f", chnage2012_2013(data))
+ "%");
break;
case "Q":
System.out
.println("Thank you for trying the US Crimes Statistics Program.");
endTime = System.currentTimeMillis();
System.out.println("Elapsed time in seconds was: "
+ (endTime - startTime) / 1000);
return;
default:
System.out
.println("Error: Invalid choice selected!! Try again.n");
break;
}
}



}

/**
* function to display menu to user
*/
static void displayMenu() {

}

public static String getInput() {
String choice;
System.out.print("nEnter your selection: ");
choice = input.next();
return choice;
}

/**
* function returns the highest murder rate for a year
* 
* @param data
* @return year with highest murder rate
*/
public static int murderRate(USCrimeClass[] data) {
int year = 0;
float maxRate = 0;
for (USCrimeClass crime : data) {
if (crime.getMurderRate() > maxRate) {
maxRate = crime.getMurderRate();
year = crime.getYear();
}
}
return year;
}

/**
* function returns the lowest murder rate for a year
* 
* @param data
* @return year with lowest murder rate
*/
public static int lowestMurderRate(USCrimeClass[] data) {
int year = 0;
float minRate = data[0].getMurderRate();
for (USCrimeClass crime : data) {
if (crime.getMurderRate() minRate = crime.getMurderRate();
year = crime.getYear();
}
}
return year;
}

/***
* 
* @param data
* @return
*/
public static int highestRobberyRate(USCrimeClass[] data) {
int year = 0;
float maxRate = 0;
for (USCrimeClass crime : data) {
if (crime.getRobberyRate() > maxRate) {
maxRate = crime.getRobberyRate();
year = crime.getYear();
}
}
return year;
}

/****
* 
* @param data
* @return
*/
public static int lowestRobberyRate(USCrimeClass[] data) {
int year = 0;
float minRate = data[0].getRobberyRate();
for (USCrimeClass crime : data) {
if (crime.getRobberyRate() minRate = crime.getRobberyRate();
year = crime.getYear();
}
}
return year;
}

/**
* function calculates the percentage change in motor vehicle theft between
* 1998-2012
* 
* @param data
* @return
*/
static float chnage1998_2012(USCrimeClass[] data) {
float change;
int motorVehicleTheftIn1998 = data[4].getMotorVehicleTheft();
int motorVehicleTheftIn2012 = data[18].getMotorVehicleTheft();
change = (float) (motorVehicleTheftIn2012 - motorVehicleTheftIn1998)
* 100 / motorVehicleTheftIn1998;
return change;
}

/***
* 
* @param data
* @return
*/
public static float chnage2012_2013(USCrimeClass[] data) {
float change;
float rate2012 = data[18].getMurderRate();
float rate2013 = data[19].getMurderRate();
change = (rate2013 - rate2012) * 100 / rate2012;
return change;
}

/***
* 
* @param data
* @return
*/
public static float chnage1994_1998(USCrimeClass[] data) {
float change;
int rate1994 = data[2].getPropertyCrime();
int rate1998 = data[6].getPropertyCrime();
change = (float) (rate1998 - rate1994) * 100 / rate1994;
return change;
}

/**
* function displays the percentage population for each consecutive year
* 
* @param data
*/
static void showPercentage(USCrimeClass[] data) {
float growth;
for (int i = 0; i growth = 100
* (float) (data[i + 1].getPopulation() - data[i]
.getPopulation()) / data[i].getPopulation();
System.out.println("[" + data[i].getYear() + "-"
+ data[i + 1].getYear() + "]: "
+ String.format("%.4f", growth) + "%");
}
}

/**
* function handles the choice given by the user
* 
* @param data
*/
static void handleMenu(USCrimeClass[] data) {

}

/***
* Read file data
* 
* @param filename
* @return
*/
public static USCrimeClass[] read(String filename) {
USCrimeClass[] stats = new USCrimeClass[20];
int count = 0;
String line;
try {
// read file
Scanner inputReader = new Scanner(new File(filename));

// ignore column name
inputReader.nextLine();
while (inputReader.hasNext()) {
line = inputReader.nextLine();
String[] data = line.split(",");
stats[count] = new USCrimeClass(Integer.parseInt(data[0]));
stats[count].setPopulation(Integer.parseInt(data[1]));
stats[count].setMurderRate(Float.parseFloat(data[5]));
stats[count].setMotorVehicleTheft(Integer.parseInt(data[18]));
stats[count].setPropertyCrime(Integer.parseInt(data[12]));
stats[count].setRobberyRate(Float.parseFloat(data[9]));
count++;
}
} catch (FileNotFoundException e) {
System.out.println(e);

}

return stats;
}

}
**********************************************

This is the class

public class USCrimeClass {
private float mRate;
private float rRate;
private int pCrime;
private int population;
private int mVehicleTheft;
private int year;

/***
* Constructor
* @param year
*/
public USCrimeClass(int year) {
this.year = year;
}

public float getMurderRate() {
return mRate;
}

public void setMurderRate(float mRate) {
this.mRate = mRate;
}

public float getRobberyRate() {
return rRate;
}

/***
* 
* @param rRate
*/
public void setRobberyRate(float rRate) {
this.rRate = rRate;
}

/***
* 
* @param pCrime
*/
public void setPropertyCrime(int pCrime) {
this.pCrime = pCrime;
}

/***
* 
* @return
*/
public int getPropertyCrime() {
return pCrime;
}

public int getPopulation() {
return population;
}

public void setPopulation(int population) {
this.population = population;
}

/***
* 
* @return
*/
public int getMotorVehicleTheft() {
return mVehicleTheft;
}

/***
* 
* @param mVehicleTheft
*/
public void setMotorVehicleTheft(int mVehicleTheft) {
this.mVehicleTheft = mVehicleTheft;
}

public int getYear() {
return year;
}
}

Answers

Not Rated (0)
Status NEW Posted 21 Jul 2017 01:07 PM My Price 12.00

Hel-----------lo -----------Sir-----------/Ma-----------dam----------- Â-----------  -----------Tha-----------nk -----------you----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------acq-----------uis-----------iti-----------on -----------of -----------my -----------pos-----------ted----------- so-----------lut-----------ion-----------.Pl-----------eas-----------e p-----------ing----------- me----------- on----------- ch-----------at -----------I a-----------m Â----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I

Not Rated(0)