Menu

[Solved]Java Part 4 Write Client Program Demonstrates Three Classes Read Employee Data Text File C Q37031652

JAVA

Part 4

Write a client program that demonstrates the above threeclasses, read employee data from a text file, create andinstantiate new Employee objects, and handles exceptions in theprocess. Code efficiency must be considered.

  1. In the client program CShw4.java, you will create variousobjects and test all the methods of the above three classes on theway you define them.

  2. Download the hw4data.txt file and place it in the root folder ofyour CShw4 project. The text file contains employee data in whicheach line contains information for one employee, in the order ofID, first name, last name, year of hire, month of hire, and day ofhire.

  3. Create an array of 50 to hold up to 50 Employee objects. Readdata from the text file to instantiate the array of employees(partially-filled array). You must use loop(s) to read a flexiblenumber of employees’ data and record the actual number ofemployees.

  4. Call the toString method of the Employee class implicitly todisplay all employees’ information.

  5. Y our program must use try…catch to handle exceptionsincluding the

    InputMismatchException andFileNotFoundException.

  6. Define a method processHireYear in the client program thataccepts an array of Employee objects and the actual number ofemployees, finds the earliest year of hire and the latest year ofhire of the employees, and displays the results. Invoke the methodto process the employee array created in the main method anddisplay the earliest year of hire and latest year of hire of thoseemployees.

hw4data.txt

23492 Amanda Jones 1990 3 28
20302 Amber Johnson 1994 8 1
10348 Brandon Brown 2000 3 15
30452 Chris Davis 1995 6 20
26472 Daniel Hall 1980 7 25
32746 Elizabeth Walker 2014 2 18
13782 Frank Thompson 2010 9 19
12203 Jack Moore 2016 2 8
21319 Kevin Young 1995 3 23
34039 Nick Turner 2003 10 28

//

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.InputMismatchException;
import java.util.Scanner;

public class CShw4 {

public static void main(String[] args) {
Date date = new Date();
Date date1 = new Date(2014,5,15);
Date date2 = new Date(date);

Person person = new Person();

Person person1 = new Person(“Alex”, “John”);

System.out.println(date);
System.out.println(date1);
System.out.println(date2);

System.out.println(person);
System.out.println(person1);

System.out.println(“Date and Date2 is same? ” +date.equals(date2));
System.out.println(“Date1 and Date2 is same? ” +date1.equals(date2));

  
try {
Scanner scanner = new Scanner(newFileInputStream(“hw4data.txt”));

try {
Employee[] employees = new Employee[50];
int count = 0;
while (scanner.hasNextLine()){
employees[count++] = newEmployee(scanner.next(),scanner.next(),
scanner.nextInt(), scanner.nextInt(),scanner.nextInt(),scanner.nextInt());
}

for (Employee employee: employees){
System.out.println(employee.toString());
}

processHireYear(employees);

}catch (InputMismatchException mismatch){

}
}catch (FileNotFoundException notFound){

}
}

private static void processHireYear(Employee[] employees) {

int earliestYear = 2019;
int latestYear = 1990;

for (Employee employee: employees){
int year =employee.getHireDate().getYear();
if (year < earliestYear){
earliestYear = year;
}

if (year > latestYear){
latestYear = year;
}
}

System.out.println(“Earliest year of hiring: ” +earliestYear);
System.out.println(“Latest year of hiring: ” + latestYear);
}
}

what I have so far

Expert Answer


Answer to JAVA Part 4 Write a client program that demonstrates the above three classes, read employee data from a text file, creat… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *