Question
Files to Submit: Employee.java TestEmployee2.java Constructor Methods Create a constructor for the Employee class that defines two parameters: one for the number and one for
Files to Submit:
Employee.java TestEmployee2.java
Constructor Methods
Create a constructor for the Employee class that defines two parameters: one for the number and one for the name. Set department, position to default values null for strings, and set salary, rank also to default values 0 for numeric values.
Create a constructor for the Employee class that defines six parameters for all six fields and sets them to these values.
Methods
In your Employee class, create a method called checkBonus(). This method will return true or false depending on whether the employee gets a bonus. The bonus is determined by their rank. If their rank is above 5, they get yearly bonus of $1,000. This method will return true if rank is above 5 and false otherwise. This method takes no parameters and returns a boolean value.
In your Employee class, create a method called displayEmployee() that prints the employees information to standard output. It should print the employees number (to 9 digits with leadings 0s filled in), name, department, position, salary and the employees rank. It should call the method checkBonus() to see if the employee gets a bonus and print the amount of the bonus if the employee will receive it. If the employee does not get a bonus, nothing is printed.
See the screen shot below for an example of output. Use printf for formatting. This method is in addition to printSalary(), which only printed the salary for testing.
TestEmployee2
The program TestEmployee2 is provided to begin testing your class. This class defines an Employee object that calls a constructor method with values for name and number. The department, position, salary and rank are added using the set methods. Finally the employee is printed out.
The end of the main method contains two commented out lines of code. The first is a call to a method you will write that returns an Employee object created with values from the contents of a file. The second line of code is that employee printed out.
Create a method in TestEmployee2 called createEmployeeFromFile() that will read data from a file and create, populate and return an Employee object. The file it will read from is called employee1.txt, which is provided. Hard code the name of the file in the method. This file contains the employees number, name, department, position, salary and rank. Create a Scanner object and use the Scanner classs methods to read the data in the file and use this data to create the Employee object. Finally return the employee object. An Employee object will be created in this method using the constructor method that takes as parameters all six fields. This employee object will be returned from this method. This method will define no parameters. The test file, employee1.txt is provided for you to test your program. I will test your program with a file that contains different values but the same format.
When you have completed this method, uncomment out the two lines of code to test the method.
Documentation
Continue documenting all the methods in the Employee class.
TestEmployee2.java :
import java.util.*; import java.io.*; public class TestEmployee2 { public static void main(String[] args) throws IOException { Employee e1 = new Employee2(7, "George Costanza"); e1.setDepartment("Front Office"); e1.setPosition("Assistant to the Traveling Secretary"); e1.setSalary(50000.0); e1.setRank(2); e1.displayEmployee(); //Employee e2 = createEmployeeFromFile(); //e2.displayEmployee(); } }
employee1.txt :
45
Elaine Benes
Editorial
Associate Editor
75000
6
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started