Question: BCS 345: Java Programming CRN 94760 Fall 2017 Instructor: Dr. Jie Li ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Objectives: Use class inheritance and class aggregation to create new classes. Catch
BCS 345: Java Programming CRN 94760 Fall 2017 Instructor: Dr. Jie Li ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
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.
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. Hint: 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 parameters. Data validation should be provided.
1) A valid year should be between 1900 and 2017, inclusive, otherwise using 2001 for the year.
2) A valid month should be between 1 and 12, inclusive, otherwise using 1 for the month.
3) A valid day should be between 1 and 31 when 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 when the month is 4, 6, 9, or 11. 1 and 28 when 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.
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 persons first name. lastName A String variable that holds a persons 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.
Part 3 - Write an Employee Class with Class Inheritance and Aggregation (70 points) The Employee class extends the Person class. It has two extra private fields: Instance Fields Description ID An int variable that holds an employees ID. hireDate A Date object that holds an employees 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 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.
Part 4 Client Program (70 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.
1. In the client program BCS345hw5.java, you should create various objects and test the methods of the above three classes on the way you define them.
2. Download the hw5data.txt file and place it in the root folder of your BCS345hw5 project. The text file contains 10 employee data in which each line contains data 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 10 to hold data for 10 employees. Read data from the text file to instantiate the array of 10 employees. Your program should catch and handle exceptions such as the InputMismatchException and FileNotFoundException.
4. Call the toString method of the Employee class to display 10 employees information.
5. Write a method processHireYear in the client program to find and display the earliest year of hire and the latest year of hire of the 10 employees. .
Extra Credit (40 points): Make a JavaFX FXML application that uses a GUI to allow user display all the employee data in a window. See the sample output.
Hints: 1. You will need to copy Date.java, Person.java, and Employee.java into the new JavaFX project order to use the Employee class. 2. Consider using ArrayList of Employee to store Employee obje
3. You dont need hw5data.txt in this part. Make a JavaFX FXML application that uses a GUI to allow user to enter new employee data window. See the sample output. You will need to copy Date.java, Person.java, and Employee.java into the new JavaFX project Consider using ArrayList of Employee to store Employee objects.
3. You dont need hw5data.txt in this part. new em
hw5data.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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
