BCS 345: Java Programming CRN 21177, 25160 JL Spring 2020...

1 answer below »
Objectives: Use class inheritance and class aggregation to create new classes. Catch and handle exceptions in the program. Write methods to process array of objects.
See the attachment.


BCS 345: Java Programming CRN 21177, 25160 JL Spring 2020 --------------------------------------------------------------------------------------------------------------------------------------------------------------- Homework 4 ⎯ Monday, April 6 Due Saturday, April 25, 11:59PM in Blackboard --------------------------------------------------------------------------------------------------------------------------------------------------------------- Objectives: Use class inheritance and class aggregation to create new classes. Catch and handle exceptions in the program. Write methods to process array of objects. Tasks: This assignment deserves 200 points. Create a Java application project with the main class named BCS345hw4. Use the default package for your project. The project contains three other classes, Date, Person, and Employee. Part 1 - Write a Date Class (30 points) The Date class should consist of three private fields: Instance Fields Description year An int variable that holds the value of a year. month An int variable that holds the value of a month. day An int variable that holds the value of a day. The Date class should also have the following public instance methods. Instance Methods Description No-arg constructor Creates a Date object and initializes year to 2001, month and day to 1. Overloaded constructor Creates a Date object and initializes the year, month, and day according to the arguments. Hints: call the setDate method to ensure data validation. Copy Constructor Create a Date object and initializes the year, month, and day using an existing Date object. getYear Returns the value in year. getMonth Returns the value in month. getDay Returns the value in day. setDate Sets the year, month and day according to the method arguments. Data validation should be provided as follows. 1) A valid year should be between 1900 and 2019, otherwise use 2001 for the year. 2) A valid month should be between 1 and 12, otherwise use 1 for the month. 3) A valid day should be between • 1 and 31 if the month is 1, 3, 5, 7, 8, 10, or 12, (which means there are 31 days in January, March, May, July, August, October, and December.) • 1 and 30 if the month is 4, 6, 9, or 11. • 1 and 28 if the month is 2, i.e., simply assume there are 28 days in February. Use 1 for the day if the value is invalid. toString Outputs the year, month, and day in the format of YYYY-MM-DD. equals Compares two Date objects’ values and returns true if they are the same, otherwise returns false. The Javadoc comments are required for the class, fields, and methods. Part 2 - Write a Person Class (30 points) The Person class should consist of two private fields: Instance Fields Description firstName A String variable that holds a person’s first name. lastName A String variable that holds a person’s last name. The Person class should also have the following public instance methods. Instance Methods Description No-arg constructor Creates a Person object and initializes firstName and lastName to “No Name”. Overloaded constructor Accepts two String arguments, creates a Person object and initializes firstName and lastName according to the arguments. Copy Constructor Create a Person object and initializes firstName and lastName using an existing Person object. getFirstName Returns the value in firstName. getLastName Returns the value in lastName. setFirstName Sets the firstName field according to a String argument. setLastName Sets the lastName field according to a String argument. toString Outputs the first name and last name of a Person object. equals Compares two Person objects’ first name and last name values and returns true if they are the same, otherwise returns false. The Javadoc comments are required for the class, fields, and methods. Part 3 - Write an Employee Class with Class Inheritance and Aggregation (60 points) The Employee class extends the Person class. It has two extra private fields: Instance Fields Description ID An int variable that holds an employee’s ID. hireDate A Date object that holds an employee’s date of hire. The Employee class should also have the following public instance methods. Instance Methods Description No-arg constructor Creates a Employee object and initializes ID to 0. The firstName and lastName fields should be initialized through the no-arg constructor of the Person class. The hireDate should be initialized by the no-arg constructor of the Date class. Overloaded constructor Accepts two String values (for first name and last name), one int value (for ID), and three int values (for year, month, and day) as arguments and creates an Employee object accordingly. Copy Constructor Create an Employee object using an existing Employee object. getID Returns the value in ID. getHireDate Returns a reference to a Date object which has the same contents as the hireDate field. setID Sets the ID field according to an int argument. The valid value for ID is positive, otherwise use 0. setHireDate Sets the hireDate field using the values of a Date object. toString This method overrides the toString method from the Object class. Outputs the first name, last name, ID, and hire date of an Employee object. Hints: use the toString method of the Person class and Date class. equals Compares two Employee objects’ firstName, lastName, ID, and hireDate values and returns true if they are the same, otherwise returns false. The Javadoc comments are required for the class, fields, and methods. Part 4 – Client Program (80 points) Write a client program that demonstrates the above three classes, read employee data from a text file, create and instantiate new Employee objects, and handles exceptions in the process. Code efficiency must be considered. 1. In the client program BCS345hw4.java, you will create various objects and test all the methods of the above three classes on the way you define them. 2. Download the hw4data.txt file and place it in the root folder of your BCS345hw4 project. The text file contains employee data in which each line contains information for one employee, in the order of ID, first name, last name, year of hire, month of hire, and day of hire. 3. Create an array of 50 to hold up to 50 Employee objects. Read data from the text file to instantiate the array of employees (partially-filled array). You must use loop(s) to read a flexible number of employees’ data and record the actual number of employees. 4. Call the toString method of the Employee class implicitly to display all employees’ information. 5. Your program must use try…catch to handle exceptions including the InputMismatchException and FileNotFoundException. 6. Define a method processHireYear in the client program that accepts an array of Employee objects and the actual number of employees, finds the earliest year of hire and the latest year of hire of the employees, and displays the results. Invoke the method to process the employee array created in the main method and display the earliest year of hire and latest year of hire of those employees. Submission: Submit one ZIP file that includes all your source code files with the following names (Don’t use any other filenames. Filenames are case-sensitive): Date.java, Person.java, Employee.java, BCS345hw4.java. Be sure to include the integrity statement I certify that this submission is my own original work with your name and RAM ID in all your source files. 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
Answered Same DayApr 20, 2021BCS345

Answer To: BCS 345: Java Programming CRN 21177, 25160 JL Spring 2020...

Aditya answered on Apr 21 2021
130 Votes
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.util.InputMismatc
hException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;
public class BCS345hw4 {
static void processHireYear(Employee e[],int size)
{
Date d;
int hire_year[] = new int[size];
for(int i =0;i {
d = e[i].getHireDate();
hire_year[i] = d.getYear();
}
Arrays.sort(hire_year);
System.out.println("");
System.out.println("Earliest Year Of Hire:...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here