Question: Your second programming assignment is an extension of the first week's assignment. You will add some methods to your software and add a menu to

Your second programming assignment is an extension of the first week's assignment. You will add some methods to your software and add a menu to the main program to allow the user to perform different operations with the list of occupations.

Your task is to edit the first programming assignment to:

  1. take into account any of the comments included with the grade for your first assignment and edit your software accordingly. You will get your first assignment back this week. You do not need to wait for this to start the assignment.
  2. make sure that the number of people employed in each occupation and the average salary are both integer data types.
  3. add a method to the list class to calculate and return the total number of people employed across all of the occupations listed (the sum of the number employed in each occupation).
  4. add a method to the list class to calculate and return the average of the salaries across all occupations. The data file has the average salary for each occupation. There is no tricky weighted calculation here -- just return the total of the average salaries divided by the count of items in the list.
  5. change your main method so that it:
    • instantiates an instance of the list class
    • calls your list class method to load the data into the array from a data file
    • then has a menu to ask the user what they wish to do, and calls the appropriate method to do so:
      • print the entire list
      • print the total number of people employed across all occupations
      • print the average of all the average salaries
      • search for the data for one occupation.
      • exit the program.

The format, design, etc. of the menu is up to you. There are many different ways to set up such a menu.

The first assignment code down below and Please add comments to the code

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Occupation.java  package Occupations; public class Occupation { private String COS; private String title; private int employment; private int avgSalary; public int getAvgSalary() { return avgSalary; } public void setAvgSalary(int avgSalary) { this.avgSalary = avgSalary; } public String getCOS() { return COS; } public void setCOS(String cOS) { COS = cOS; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public int getEmployment() { return employment; } public void setEmployment(int employment) { this.employment = employment; } @Override public String toString() { return "Occupation [COS=" + COS + ", title=" + title + ", employment=" + employment + ", avgSalary=" + avgSalary + "]"; } public Occupation(String cOS, String title, int employment, int avgSalary) { super(); COS = cOS; this.title = title; this.employment = employment; this.avgSalary = avgSalary; } }

OccupationList.java

package Occupations; import java.io.File; import java.util.Scanner; public class OccupationList { private Occupation[] occupations; private int numberOfOccupations; public OccupationList() { occupations = new Occupation[1000]; loadData(); } public void loadData() { try { Scanner infile = new Scanner(new File("occupations.txt")); int count = 0; String COS; String title; int employment; int avgSalary; while (infile.hasNextLine()) { COS = infile.nextLine(); title = infile.nextLine(); employment = Integer.parseInt(infile.nextLine().replace(",", "")); avgSalary = Integer.parseInt(infile.nextLine().replace(",", "")); // create an object for occupation and add to array occupations occupations[count] = new Occupation(COS, title, employment, avgSalary); count++; } numberOfOccupations = count; infile.close(); } catch (Exception e) { e.printStackTrace(); } } public void searchOccupationByCOS(String COS) { for (int i = 0; i < numberOfOccupations; i++) { if (occupations[i].getCOS().equals(COS)) { System.out.println(occupations[i]); return; } } System.out.println("Code was not found in the list"); } public void searchOccupationByTitle(String title) { for (int i = 0; i < numberOfOccupations; i++) { if (occupations[i].getTitle().equals(title)) { System.out.println(occupations[i]); return; } } System.out.println("Title was not found in the list"); } public void printOccupationData() { for (int i = 0; i < numberOfOccupations; i++) System.out.println(occupations[i]); } }

Main.java

package Occupations; import java.util.Scanner; public class Main { public static void main(String[] args) { OccupationList occList = new OccupationList(); Scanner scanner = new Scanner(System.in); System.out.println("Loading Data..."); System.out.println("Data Loaded"); System.out.println("-----------------------------------"); String title = "Software Developers, Applications"; System.out.println("Searching Title :" + title); occList.searchOccupationByTitle(title); System.out.println("-----------------------------------"); String COS = "15-1132"; System.out.println("Searching COS :" + COS); occList.searchOccupationByCOS(COS); System.out.println("-----------------------------------"); System.out.println("Printing all occupations"); occList.printOccupationData(); scanner.close(); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!