Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA: You can see where the errors are. How do I make it so that it calls the methods properly (in bold) from the USCrimeClass

JAVA: You can see where the errors are. How do I make it so that it calls the methods properly(in bold) from the USCrimeClass file to Driver file? The need for an argument to match is throwing me off. How is it done properly?

// Start of Driver.java file

import java.io.File;

import java.io.FileNotFoundException;

import java.util.Arrays;

import java.util.Scanner;

public class Driver {

public static void main(String[] args) throws FileNotFoundException {

int row = 20;

int col = 20;

int i = 0;

String quit = null;

String[] array = new String[col];

double[][] storeAll = new double[row][col];

USCrimeClass nb = new USCrimeClass();

File myFile = new File(args[0]);

Scanner inFile = new Scanner(myFile);

String oneLine = inFile.nextLine();

array = oneLine.split(",");

//for (String title : array) {

//System.out.println(Arrays.toString(array));

//}

//System.out.println(oneLine);

while (inFile.hasNextLine()) {

oneLine = inFile.nextLine();

String array1[] = oneLine.split(",");

nb.storeArrays(array1, i, storeAll);

i++;

}

System.out.println(Arrays.toString(array));

System.out.println(java.util.Arrays.deepToString(storeAll));

inFile.close();

}

public void runProgram(String quit) {

Scanner in = new Scanner(System.in);

USCrimeClass nb = new USCrimeClass();

while(!quit.trim().equalsIgnoreCase("q")) {

System.out.println("********** Welcome to the US Crime Statistical Application **************************");

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

System.out.println(" \t1. What were the percentages in population for each consecutive year from 1994-2013?" +

" \t2. What year was the Murder rate the highest?" +

" \t3. What year was the Murder rate the lowest?" +

" \t4. What year was the Robbery rate the highest?" +

" \t5. What year was the Robbery rate the lowest?" +

" \t6. Quit the program" +

" Enter your selection: ");

String choice = in.next();

switch (choice) {

case "1": nb.percentPopulation();

break;

case "2": nb.highestMurder();

break;

case "3": nb.lowestMurder();

break;

case "4": nb.highestRobbery();

break;

case "5": nb.lowestRobbery();

break;

case "Q":

case "q": System.out.println("Thank you for trying the US Crimes Statistics Program.");

quit = "q";

break;

default: System.out.println("Invalid entry, please try again");

}

}

}

}

// Start of file named USCrimeClass.java

public class USCrimeClass {

int year, population, murder, rape, robbery, assault, property,

burglary, theft, motorTheft;

double violentRate, murderRate, rapeRate, robberyRate, assaultRate,

propertyRate, burglaryRate, theftRate, motorTheftRate;

public USCrimeClass() {

}

public USCrimeClass(int year, int population, int murder, int rape, int robbery, int assault, int property,

int burglary, int theft, int motorTheft, double violentRate, double murderRate, double rapeRate,

double robberyRate, double assaultRate, double propertyRate, double burglaryRate, double theftRate,

double motorTheftRate) {

this.year = year;

this.population = population;

this.murder = murder;

this.rape = rape;

this.robbery = robbery;

this.assault = assault;

this.property = property;

this.burglary = burglary;

this.theft = theft;

this.motorTheft = motorTheft;

this.violentRate = violentRate;

this.murderRate = murderRate;

this.rapeRate = rapeRate;

this.robberyRate = robberyRate;

this.assaultRate = assaultRate;

this.propertyRate = propertyRate;

this.burglaryRate = burglaryRate;

this.theftRate = theftRate;

this.motorTheftRate = motorTheftRate;

}

public double [][] storeArrays(String array1[], int i, double[][] storeAll) {

for(int j = 0; j < array1.length; j++) {

storeAll[i][j] = Double.parseDouble(array1[j]);

}

return storeAll;

}

public void percentPopulation(double storeAll[][]) {

double total1 = (storeAll[1][1] / storeAll[0][1]) * 100;

System.out.println("The total percentage growth from 1994 to 1995 is: " + total1);

double total2 = (storeAll[2][1] / storeAll[1][1]) * 100;

System.out.println("The total percentage growth from 1995 to 1996 is: " + total2);

double total3 = (storeAll[3][1] / storeAll[2][1]) * 100;

System.out.println("The total percentage growth from 1996 to 1997 is: " + total3);

double total4 = (storeAll[4][1] / storeAll[3][1]) * 100;

System.out.println("The total percentage growth from 1997 to 1998 is: " + total4);

double total5 = (storeAll[5][1] / storeAll[4][1]) * 100;

System.out.println("The total percentage growth from 1998 to 1999 is: " + total5);

double total6 = (storeAll[6][1] / storeAll[5][1]) * 100;

System.out.println("The total percentage growth from 1999 to 2000 is: " + total6);

double total7 = (storeAll[7][1] / storeAll[6][1]) * 100;

System.out.println("The total percentage growth from 2000 to 2001 is: " + total7);

double total8 = (storeAll[8][1] / storeAll[7][1]) * 100;

System.out.println("The total percentage growth from 2001 to 2002 is: " + total8);

double total9 = (storeAll[9][1] / storeAll[8][1]) * 100;

System.out.println("The total percentage growth from 2002 to 2003 is: " + total9);

double total10 = (storeAll[10][1] / storeAll[9][1]) * 100;

System.out.println("The total percentage growth from 2003 to 2004 is: " + total10);

double total11 = (storeAll[11][1] / storeAll[10][1]) * 100;

System.out.println("The total percentage growth from 2004 to 2005 is: " + total11);

double total12 = (storeAll[12][1] / storeAll[11][1]) * 100;

System.out.println("The total percentage growth from 2005 to 2006 is: " + total12);

double total13 = (storeAll[13][1] / storeAll[12][1]) * 100;

System.out.println("The total percentage growth from 2006 to 2007 is: " + total13);

double total14 = (storeAll[14][1] / storeAll[13][1]) * 100;

System.out.println("The total percentage growth from 2007 to 2008 is: " + total14);

double total15 = (storeAll[15][1] / storeAll[14][1]) * 100;

System.out.println("The total percentage growth from 2008 to 2009 is: " + total15);

double total16 = (storeAll[16][1] / storeAll[15][1]) * 100;

System.out.println("The total percentage growth from 2009 to 2010 is: " + total16);

double total17 = (storeAll[17][1] / storeAll[16][1]) * 100;

System.out.println("The total percentage growth from 2010 to 2011 is: " + total17);

double total18 = (storeAll[18][1] / storeAll[17][1]) * 100;

System.out.println("The total percentage growth from 2011 to 2012 is: " + total18);

double total19 = (storeAll[19][1] / storeAll[18][1]) * 100;

System.out.println("The total percentage growth from 2012 to 2013 is: " + total19);

}

public double highestMurder(double storeAll[][]) {

double highestMurder = 0;

for (int i = 0; i < storeAll.length; i++) {

double value = storeAll[i][5];

if(value > highestMurder) {

highestMurder = value;

}

}

return highestMurder;

}

public double lowestMurder(double storeAll[][]) {

double lowestMurder = 100000000;

for(int i = 0; i < storeAll.length; i++) {

double value = storeAll[i][5];

if (lowestMurder == value)

lowestMurder = value;

else if (value < lowestMurder)

lowestMurder = value;

else

System.out.println();;

}

return lowestMurder;

}

public double highestRobbery(double storeAll[][]) {

double highestRobbery = 0;

for (int i = 0; i < storeAll.length; i++) {

double value = storeAll[i][5];

if(value > highestRobbery) {

highestRobbery = value;

}

}

return highestRobbery;

}

public double lowestRobbery(double storeAll[][]) {

double lowestRobbery = 10000000;

for(int i = 0; i < storeAll.length; i++) {

double value = storeAll[i][5];

if (value < lowestRobbery)

lowestRobbery = value;

else if (value > lowestRobbery)

System.out.println();

else

System.out.println();;

}

return lowestRobbery;

}

// Getters and Setters

public int getYear() {

return year;

}

public void setYear(int year) {

this.year = year;

}

public int getPopulation() {

return population;

}

public void setPopulation(int population) {

this.population = population;

}

public int getMurder() {

return murder;

}

public void setMurder(int murder) {

this.murder = murder;

}

public int getRape() {

return rape;

}

public void setRape(int rape) {

this.rape = rape;

}

public int getRobbery() {

return robbery;

}

public void setRobbery(int robbery) {

this.robbery = robbery;

}

public int getAssault() {

return assault;

}

public void setAssault(int assault) {

this.assault = assault;

}

public int getProperty() {

return property;

}

public void setProperty(int property) {

this.property = property;

}

public int getBurglary() {

return burglary;

}

public void setBurglary(int burglary) {

this.burglary = burglary;

}

public int getTheft() {

return theft;

}

public void setTheft(int theft) {

this.theft = theft;

}

public int getMotorTheft() {

return motorTheft;

}

public void setMotorTheft(int motorTheft) {

this.motorTheft = motorTheft;

}

public double getViolentRate() {

return violentRate;

}

public void setViolentRate(double violentRate) {

this.violentRate = violentRate;

}

public double getMurderRate() {

return murderRate;

}

public void setMurderRate(double murderRate) {

this.murderRate = murderRate;

}

public double getRapeRate() {

return rapeRate;

}

public void setRapeRate(double rapeRate) {

this.rapeRate = rapeRate;

}

public double getRobberyRate() {

return robberyRate;

}

public void setRobberyRate(double robberyRate) {

this.robberyRate = robberyRate;

}

public double getAssaultRate() {

return assaultRate;

}

public void setAssaultRate(double assaultRate) {

this.assaultRate = assaultRate;

}

public double getPropertyRate() {

return propertyRate;

}

public void setPropertyRate(double propertyRate) {

this.propertyRate = propertyRate;

}

public double getBurglaryRate() {

return burglaryRate;

}

public void setBurglaryRate(double burglaryRate) {

this.burglaryRate = burglaryRate;

}

public double getTheftRate() {

return theftRate;

}

public void setTheftRate(double theftRate) {

this.theftRate = theftRate;

}

public double getMotorTheftRate() {

return motorTheftRate;

}

public void setMotorTheftRate(double motorTheftRate) {

this.motorTheftRate = motorTheftRate;

}

}

// Excel file named Crime.csv

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Database Programming

Authors: Chris Fehily

1st Edition

1937842312, 978-1937842314

More Books

Students also viewed these Databases questions

Question

How many Tables Will Base HCMSs typically have? Why?

Answered: 1 week ago

Question

What is the process of normalization?

Answered: 1 week ago