The main objective of this project is to be able to design, create and utilize c
ID: 3718847 • 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
the user must be able to manually enter each user's information
Explanation / Answer
import java.util.Scanner;
class Employee
{
private String firstName,lastName,id,phone;
private double yearlySalary,bonusPercent;
public void setLastName(String lastName)
{
this.lastName = lastName;
}
public void setFirstName(String firstName)
{
this.firstName = firstName;
}
public void setId(String id)
{
this.id = id;
}
public void setPhone(String phone)
{
this.phone = phone;
}
public void setYearlySalary(double yearlySalary)
{
this.yearlySalary = yearlySalary;
}
public void setBonusPercent(double bonusPercent)
{
this.bonusPercent = bonusPercent;
}
public boolean inputAll()
{
Scanner input = new Scanner(System.in);
System.out.println("Enter first name of employee : ");
firstName = input.next();
System.out.println("Enter last name of employee : ");
lastName = input.next();
if(lastName = " ")
return false;
else
{
System.out.println("Enter id of employee : ");
id = input.next();
System.out.println("Enter phone of employee : ");
phone = input.next();
System.out.println("Enter yearly salary of employee : ");
yearlySalary = input.nextDouble();
System.out.println("Enter bonus percent of employee : ");
bonusPercent = input.nextDouble();
return true;
}
}
public String toString()
{
return " Employee Id : "+id +" First Name : "+firstName +" Last Name : "+lastName +
" Phone : "+phone + " Yearly Salary : "+yearlySalary + " Bonus Percent : "+bonusPercent;
}
public boolean equals(Employee emp)
{
if(this.firstName == emp.firstName && this.lastName == emp.lastName && this.id == emp.id && this.phone == emp.phone && this.yearlySalary == emp.yearlySalary && this.bonusPercent == emp.bonusPercent)
return true;
else
return false;
}
}
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;
}
}
}
}
Output:
Employee Id : 57831 First Name : Audie Last Name : Murphy Phone : 619-555-1212 Yearly Salary : 40000.0 Bonus Percent : 5.0
Employee No. 1
Enter first name of employee :
Enter last name of employee :
Enter id of employee :
Enter phone of employee :
Enter yearly salary of employee :
Enter bonus percent of employee :
Employee Match : true
Employee Id : 57898 First Name : Candy Last Name : Smith Phone : 619-585-1278 Yearly Salary : 35000.0 Bonus Percent : 4.56
Employee No. 2
Do ask if any doubt. Please upvote.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.