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: | 314 Weeks 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
Java question
When I run the following programs in NETBEANS it runs but instantly displays this message.
I need this program to run in netbeans so take note of the package info.
Â
"
run:
********** Welcome to the US Crime Statistical Application **************************
Usage: "java UserCrimeStatsApp Crime.csv
BUILD SUCCESSFUL (total time: 0 seconds)
"
Â
I understand i am getting this message because of this statement.
if (args.length != 1) {
System.out.println("Usage: "java UserCrimeStatsApp Crime.csv");
return;
Â
I do not understand how to get it to run the program properly.
Â
If you could give me step by step instructions on how to run this properly it would be appreciated.
The only place i see to read the Crime.csv is line 195 of the test program. is that the only place i need to put the this file information?
If you could include a lot of //notes explaining a ton of stuff through-out the file it would be awesome.
If you see any ways to make the program more unique so i don't turn in the same thing as another student that would also be good.
Â
Â
I will attach the assignment, the file to read the information from, and the 2 java files./*
 * 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 uscrimeclass;
/**
 *
 * @author Izzy
 */
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.io.File;
/**
 *
 * @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[] usCrimeData = readFileData(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"
               + "Q. Quit the program";
         System.out.println(menu);
         choice = getInput();
         System.out.println();
         switch (choice) {
         case "1":
            getPercentage(usCrimeData);
            break;
         case "2":
            System.out.println("The Murder rate was highest in "
                  + murderRate(usCrimeData));
            break;
         case "3":
            System.out.println("The Murder rate was lowest in "
                  + lowestMurderRate(usCrimeData));
            break;
         case "4":
            System.out.println("The Robbery rate was highest in "
                  + getHighRR(usCrimeData));
            break;
         case "5":
            System.out.println("The Robbery rate was lowest in "
                  + getLwRR(usCrimeData));
            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;
   }
   /***
   *
   * @param usCrimeData
   * @return
   */
   public static int murderRate(USCrimeClass[] usCrimeData) {
      int year = 0;
      float maxRate = 0;
      for (USCrimeClass crime : usCrimeData) {
         if (crime.getMurderRate() > maxRate) {
            maxRate = crime.getMurderRate();
            year = crime.getYear();
         }
      }
      return year;
   }
   /***
   *
   * @param usCrimeData
   * @return
   */
   public static int lowestMurderRate(USCrimeClass[] usCrimeData) {
      int year = 0;
      float minRate = usCrimeData[0].getMurderRate();
      for (USCrimeClass crime : usCrimeData) {
         if (crime.getMurderRate() < minRate) {
            minRate = crime.getMurderRate();
            year = crime.getYear();
         }
      }
      return year;
   }
   /***
   *
   * @param usCrimeData
   * @return
   */
   public static int getHighRR(USCrimeClass[] usCrimeData) {
      int year = 0;
      float maxRate = 0;
      for (USCrimeClass crime : usCrimeData) {
         if (crime.getRobberyRate() > maxRate) {
            maxRate = crime.getRobberyRate();
            year = crime.getYear();
         }
      }
      return year;
   }
   /****
   *
   * @param usCrimeData
   * @return
   */
   public static int getLwRR(USCrimeClass[] usCrimeData) {
      int year = 0;
      float minRate = usCrimeData[0].getRobberyRate();
      for (USCrimeClass crime : usCrimeData) {
         if (crime.getRobberyRate() < minRate) {
            minRate = crime.getRobberyRate();
            year = crime.getYear();
         }
      }
      return year;
   }
  Â
   /***
   *
   * @param usCrimeData
   */
   public static void getPercentage(USCrimeClass[] usCrimeData) {
      float growth;
      for (int i = 0; i < usCrimeData.length - 1; i++) {
         growth = 100
               * (float) (usCrimeData[i + 1].getPopulation() - usCrimeData[i]
                     .getPopulation()) / usCrimeData[i].getPopulation();
         System.out.println("[" + usCrimeData[i].getYear() + "-"
               + usCrimeData[i + 1].getYear() + "]: "
               + String.format("%.4f", growth) + "%");
      }
   }
  Â
   /***
   *
   * @param filename
   * @return
   */
   public static USCrimeClass[] readFileData(String filename) {
      USCrimeClass[] data = new USCrimeClass[20];
      int noLine = 0;
      String singleLine;
      try {
         // readFileData file
         Scanner console = new Scanner(new File("C:/Users/Izzy/Desktop/Crime.csv"));
         // ignore column name
         console.nextLine();
         while (console.hasNext()) {
            singleLine = console.nextLine();
            String[] usCrimeData = singleLine.split(",");
            data[noLine] = new USCrimeClass(Integer.parseInt(usCrimeData[0]));
            data[noLine].setRobberyRate(Float.parseFloat(usCrimeData[9]));
            data[noLine].setPopulation(Integer.parseInt(usCrimeData[1]));
            data[noLine].setMurderRate(Float.parseFloat(usCrimeData[5]));
            noLine++;
         }
        Â
         //close I/O
         console.close();
      } catch (FileNotFoundException e) {
         System.out.println(e);
      }
     Â
     Â
      return data;
   }
}/*
 * 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 uscrimeclass;
/**
 *
 * @author Izzy
 */
public class USCrimeClass {
   private float murderRate;
   private float robberyRate;
   private int popGrowth;
   private int year;
  Â
   /**
   *
   * @param year
   */
   public USCrimeClass(int year) {
      this.year = year;
   }
   public float getMurderRate() {
      return murderRate;
   }
   public void setMurderRate(float murderRate) {
      this.murderRate = murderRate;
   }
   public float getRobberyRate() {
      return robberyRate;
   }
   /***
   *
   * @param robberyRate
   */
   public void setRobberyRate(float robberyRate) {
      this.robberyRate = robberyRate;
   }
   public int getPopulation() {
      return popGrowth;
   }
   public void setPopulation(int popGrowth) {
      this.popGrowth = popGrowth;
   }
   public int getYear() {
      return year;
   }
}
----------- Â ----------- 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