Question: This class will contain six data fields and methods to set, get and manipulate these fields. You must reate an array of Employee objects, populate

This class will contain six data fields and methods to set, get and manipulate these fields. You must reate an array of Employee objects, populate and display the values. You will not be changing your class, but you will have to submit it.

The method

Construct a method called createEmployeeArrayFromFile(). This method will create and return an array of Employee objects.

Hard code the file name, (example)________, into your program. The file will contain six lines for each employee: an employee number, name, department, position, salary, and rank and has data for 10 employees.

Construct the array. There will be ten of these and this can be hard coded. Although we are reading this information from a file and it would be more useful to simply add objects as we go along, an array needs a size when it is created. (The ArrayList class does not, and is preferable in this respect, but we will stick to an array.)

Create a loop and iterate through the file, creating elements of the Employee array. If you didnt know how much data was stored in the file, you would use a while loop, but since you know it will contain exactly 10 employees, you can use a while loop or for loop.

Finally, the method must return the array.

printEmployeeArray()

Create a void method called printEmployeeArrray() that takes one parameter, an Employee array. Loop through the array and print the values using the Employee objects displayEmployee() method.

The main method

Empty the main method. Create an Employee array variable and make it equal to the createEmployeeArrayFromFile() method call. Then call the printEmployeeArray() method and send it one argument: the Employee array.

You should know:

If you use a while loop to iterate through the file, you will need an int variable to act as an index for the array. Make sure to initialize this variable to 0 before the loop begins and increment it within the loop.

You may encounter the nextLine issue as you read through the file. This occurs when you read a number using nextInt or nextDouble and then use the nextLine method. This is remedied by using a dummy nextLine call in between nextInt and nextLine.

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!