Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA Your task is to create software for an occupation list object that uses a linked list instead of an array, then substitute the linked

JAVA

Your task is to create software for an occupation list object that uses a linked list instead of an array, then substitute the linked list based occupation list class for the array-based occupation list class in the assignment you have been working on. (I attached what i have from previous assignment)

If you do this correctly, the class will have methods with names and parameters matching those in the array-based occupation list class has, so you should be able to just substitute it for your existing array-based occupation list class without changing the project class or the occupation class.

To make the linked list class work, you should also have a ListNode class. The ListNode class is simple. A ListNode has two properties -- data and a link (a pointer) to the next node in the list. In this case, the data is an Occupation object. The link is of the same datatype as the ListNode class itself -- ListNode. It will be a property (variable) referencing another ListNode object. You will need at least one constructor, along with set and get methods for the two properties.

If correctly implemented, you should not need to change the project class it should work with a list class whether that list is implemented with an array or a linked list. The internal details of the data structure within the list class should not affect the users view of operations from outside the data structure. In other words, our classes should be encapsulated.

The project class, including the main method, and thew occupation class should stay the same as they were in the previous assignment.

The software to load the list from a data file should read the data into properties of an occupation object, or into temporary variables and then put the data into an occupation object. Then the loop should instantiate a new list node with a null pointer, and append this node to your linked list. It will be easier to to do this if you have an append() method in your list class.

You will not need a count of the number of items in your list -- instead, your loops to search and print the list should continue to go through the list until they reach a null pointer.

This is the code that I have from previous assignment:

Main class:

package ListOfOccupations; import ListOfOccupations.OccupationList; import ListOfOccupations.Occupation; public class Main { public static void main(String[] args) throws Exception { // instatiate a occupationList object OccupationList mylist = new OccupationList(); // load the list with data from a file mylist.loadList(); // print the list System.out.println(mylist); // call a method to search the list } } 

Occupation Class

package ListOfOccupations; public class Occupation { private String socn; // Standard Occupational Classification number private String title; // the title of the occupation private int employment; // number of people employed at this position in United States private int salary; // salary for this position // constructors Occupation() { } Occupation(String socn, String title, int employment, int salary) { this.socn = socn; this.title = title; this.employment = employment; this.salary = salary; } // end Occupation() // mutator methods public void setSocn(String socn) { this.socn = socn; } // end set Socn() public void setTitle(String title) { this.title = title; } // end set title() public void setEmployment(int employment) { this.employment = employment; } // end set employment public void setSalary(int salary) { this.salary = salary; } // end set salary //accessor methods public String getSocn() { return this.socn; } // end getSoc public String getTitle() { return this.title; } // end getTitle public int employment() { return this.employment; } // end getEmployment public int getSalary() { return this.salary; } //end getSalary public String toString() { String data = "SOC: " + this.socn + " TITLE: " + this.title + " EMPLOYMENT: " + this.employment + " SALARY: " + this.salary + " "; return data; } // end toString() } // end class Occupation

Occupation List Class

public class OccupationList { private Occupation[] myList = new Occupation[1000]; // a array to hold a list of Occupation objects private int count = 0; // the number of array elements that actually contain data // method to load the array from datafile public void loadList() throws Exception { // temporary variables to hold the data from the file String inSocn; String inTitle; int inEmployment; int inSalary; int i = 0; // loop counter //Create a File class object linked to the name of the file to read File data = new File("data.txt"); // Create a Scanner named data to read input stream from the file Scanner infile = new Scanner(data); // loop to read the data ito temporat variables and then create each object and put it in the array while (infile.hasNextLine()) { //read data from the file into temporary variables inSocn = infile.nextLine(); inTitle = infile.nextLine(); inEmployment = Integer.parseInt(infile.nextLine()); inSalary = Integer.parseInt (infile.nextLine()); this.myList[i] = new Occupation(inSocn, inTitle, inEmployment, inSalary); i++; } // end while update count; this.count = i; //method to find Occupation by job name System.out.println("Please enter Job Name to search for the position:"); String input0 = "Chief Executives"; for (String tile : inTitle); if (inTitle.equals(input0)){ System.out.println("Job Name found" + input0 ); } // method to search by COS System.out.println("Please enter the Standard Occupational Classification number to search for the job number:"); String input1 = "11-1011"; for (String socn: inSocn); if (inSocn.equals(input1)){ System.out.println("Standard Occupational Classification number found" + input1 ); } // method to print the list System.out.println(myList); // iterate the array, using the occupation class toString() to print the data for each item } //END CLASS

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

More Books

Students also viewed these Databases questions

Question

Example. Evaluate 5n+7 lim 7-00 3n-5

Answered: 1 week ago