The main objective of this project is to be able to design, create and utilize c
ID: 3713618 • Letter: T
Question
The main objective of this project is to be able to design, create and utilize classes and objects. You are to write a class based on the following UML. Your class will be called “Employee” and reside in a source file named “EmployeeTest.java”.
##############(UML)#####################
Employee class:
- lastName: String
- firstName: String
- id: String
- phone: String
- yearlySalary: double
- bonus Percent: double
+ setLastName( String )
+ getLastName(): String
+ setFirstName( String)
+ getFirstName(): String
+ setId( String )
+ getId(): String
+ setPhone( String )
+ getPhone(): String
+ setYearlySalary( double )
+ getYearlySalary(): double
+ setBonusPercent( double )
+ getBonusPercent(): double
+ calcBonus( percent: double)
+ calcMonthlyPay()
+ inputAll(): boolean
+ toString(): String
+ equals(): boolean
###########################################
###########(The template)##########
package employeetest;
import java.util.Scanner;
class Employee {}
public class EmployeeTest {
public static final int MAX_EMPLOYEES = 5;
public static void main(String[] args) {
Employee employee[] = new Employee[MAX_EMPLOYEES];
employee[0] = new Employee();
employee[0].setLastName("Murphy");
employee[0].setFirstName("Audie");
employee[0].setId("57831");
employee[0].setPhone("619-555-1212");
employee[0].setYearlySalary(40000);
employee[0].setBonusPercent(5);
System.out.println(employee[0]);
for (int lp = 1; lp < MAX_EMPLOYEES; lp++) {
employee[lp] = new Employee();
System.out.println("Employee No. " + (lp + 1));
if (employee[lp].inputAll()) {
if (employee[lp].equals(employee[0])) {
System.out.println("Employee Match : true");
} else {
System.out.println("Employee Match : false");
}
System.out.println(employee[lp]);
} else {
System.out.println("NO Information for Employee " + (lp + 1));
lp = MAX_EMPLOYEES;
}
}
}
}
#################################
##########(The assignment)##########
The class Employee will be used to define or instantiate objects that contain the fields and the methods defined in the UML diagram above.The“set” methods will allow data to be passed into an object. The “get” methods will allow data to be retrieved from an object.The “inputAll” method will allow data to be entered (from the keyboard) by a user directly into the instant variables of an object.You may use the Scanner class to handle keyboard input. This method will return a Boolean value based on whether the user enters a Last Name for the Employee. If no last name is entered, none of the other employee information will be prompted for. The inputAll() method should prompt for the
following information and set the values of the object:
• lastName: String(setLastName)
• firstName: String(setFirstName)
• id: String(setId)
• phone: String(setPhone)
• yearlySalary: double(setYearlySalary)
• bonusPercent: double(setBonusPercent)
The yearly bonus is calculated by multiplying the yearly salary by the
bonus percentage.
The monthly salary is calculated by adding the yearly salary and the yearly bonus, then dividing this sum by 12.
The “toString” method
will return a string containing the formatted output. It should look like:
Employee Information
Last Name: Murphy
First Name: Audie
Employee ID: 57831
Employee Phone: 619-555-1212
Yearly Salary: $40000.00
Yearly Bonus: $2000.00
Monthly Salary: $3500.00
after the employee information has been entered for employee 2-5, the “equals” method will be used to
determine if the first and last name of the current employee match the first and last name of the first
employee. If both first and last names match, the “equals” method returns true. “false” otherwise.
You MUST use the main method in the “EmployeeTest” class below to test your class.
public class EmployeeTest {
public static final int MAX_EMPLOYEES = 5;
public static void main(String[] args) {
Employee employee[] = new Employee[MAX_EMPLOYEES];
employee[0] = new Employee();
employee[0].setLastName("Murphy");
employee[0].setFirstName("Audie");
employee[0].setId("57831");
employee[0].setPhone("619-555-1212");
employee[0].setYearlySalary(40000);
employee[0].setBonusPercent(5);
System.out.println(employee[0]);
for (int lp = 1; lp < MAX_EMPLOYEES; lp++) {
employee[lp] = new Employee();
System.out.println("Employee No. " + (lp + 1));
if (employee[lp].inputAll()) {
if (employee[lp].equals(employee[0])) {
System.out.println("Employee Match : true");
} else {
System.out.println("Employee Match : false");
}
System.out.println(employee[lp]);
} else {
System.out.println("NO Information for Employee " + (lp + 1));
lp = MAX_EMPLOYEES;
}
}
}
}
#######################################
Sample Output
Employee Information
Last Name : Murphy
First Name : Audie
Employee ID : 57831
Employee Phone : 619-555-1212
Yearly Salary : $40000.00
Yearly Bonus : $2000.00
Monthly Salary : $3500.00
Employee No. 2
Enter Last Name : York
Enter First Name : Alvin
Enter Employee Id : 94834
Enter Phone Number : 619-555-9874
Enter Yearly Salary : $36000
Enter Yearly Bonus (%) : 2
Employee Match : false
Employee Information
Last Name : York
First Name : Alvin
Employee ID : 94834
Employee Phone : 619-555-9874
Yearly Salary : $36000.00
Yearly Bonus : $720.00
Monthly Salary : $3060.00
Employee No. 3
Enter Last Name :
NO Information for Employee 3
Explanation / Answer
import java.util.*;
class Employee
{
private String id;
private String lastName;
private String firstName;
private String phone;
private double yearlySalary;
private double yearlyBonus;
public Employee()
{
}
public void setFirstName(String firstName)
{
this.firstName = firstName;
}
public String getFirstName()
{
return firstName;
}
public void setLastName(String lastName)
{
this.lastName = lastName;
}
public String getLastName()
{
return lastName;
}
public void setId(String id)
{
this.id = id;
}
public String getId()
{
return id;
}
public void setPhone(String phone)
{
this.phone = phone;
}
public String getPhone()
{
return phone;
}
public void setYearlySalary(double yearlySalary)
{
this.yearlySalary = yearlySalary;
}
public double getYearlySalary()
{
return yearlySalary;
}
public void setYearlyBonus(double yearlyBonus)
{
this.yearlyBonus = yearlyBonus;
}
public double getYearlyBonus()
{
return yearlyBonus;
}
public double calcBonus()
{
return yearlySalary*yearlyBonus/100;
}
public double calcMonthlyPay()
{
return yearlySalary/12;
}
public String toString()
{
return " Last Name : "+lastName+" First Name : "+firstName+" Employee ID : "+id+" Employee Phone : "+phone+" Yearly Salary : $"+yearlySalary+" Yearly Bonus : $"+yearlyBonus+" Monthly Salary : $"+calcMonthlyPay();
}
public boolean equals(Employee E)
{
if(this.firstName == E.firstName && this.lastName == E.lastName)
return true;
else
return false;
}
public boolean inputAll()
{
Scanner scan = new Scanner(System.in);
System.out.println(" Enter the Last Name of the Employee");
lastName = scan.next();
if(lastName == " ")
return false;
System.out.println(" Enter the First Name of the Employee");
firstName = scan.next();
System.out.println(" Enter the ID of the Employee");
id = scan.next();
System.out.println(" Enter the Phone of the Employee");
phone = scan.next();
System.out.println(" Enter the Annual Salary of the Employee");
yearlySalary = scan.nextDouble();
System.out.println(" Enter the Annual Bonus of the Employee");
yearlyBonus = scan.nextDouble();
return true;
}
}
class EmployeeTest
{
public static final int MAX_EMPLOYEES = 5;
public static void main(String[] args)
{
Employee employee[] = new Employee[MAX_EMPLOYEES];
System.out.println(" Employee Information");
employee[0] = new Employee();
employee[0].setLastName( "Murphy" );
employee[0].setFirstName( "Audie" );
employee[0].setId( "57831" );
employee[0].setPhone( "619-555-1212" );
employee[0].setYearlySalary( 40000 );
employee[0].setYearlyBonus(2);
employee[0].calcBonus();
employee[0].calcMonthlyPay();
System.out.println( employee[0] );
employee[1] = new Employee();
if(employee[1].inputAll() == true)
System.out.println( employee[1] );
System.out.println(" Matches : "+employee[0].equals(employee[1]));
}
}
Output:
Employee Information
Last Name : Murphy
First Name : Audie
Employee ID : 57831
Employee Phone : 619-555-1212
Yearly Salary : $40000.0
Yearly Bonus : $2.0
Monthly Salary : $3333.3333333333335
Enter the Last Name of the Employee York
Enter the First Name of the Employee Alvin
Enter the ID of the Employee 94834
Enter the Phone of the Employee 619-555-9874
Enter the Annual Salary of the Employee 36000
Enter the Annual Bonus of the Employee 2
Last Name : York
First Name : Alvin
Employee ID : 94834
Employee Phone : 619-555-9874
Yearly Salary : $36000.0
Yearly Bonus : $2.0
Monthly Salary : $3000.0
Matches : false
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.