The main objective of this project is to be able to design, create and utilize c
ID: 3824957 • 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 diagram. Your class will be called “Employee” and reside in a source file named “Employee.java”.
Employee class
lastName: String
firstName: String
id: String
phone: String
yearlySalary: double
bonus: double
monthlySalary: double
+ setLastName( String )
+ getLastName(): String
+ setFirstName( String )
+ getFirstName(): String
+ setId( String )
+ getId(): String
+ setPhone( String )
+ getPhone(): String
+ setYearlySalary( double )
+ getYearlySalary(): double
+ calcBonus( percent: double )
+ calcMonthlyPay()
+ inputAll(): boolean
+ toString(): String
+ equals(): boolean
Assignment Task(s)
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 “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. If you instantiate the Employee class into an object (e.g., person1), the main method is ignored.
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].calcBonus( 5 );
employee[0].calcMonthlyPay();
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())
{
employee[lp].calcMonthlyPay();
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 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 diagram. Your class will be called “Employee” and reside in a source file named “Employee.java”.
Employee class
lastName: String
firstName: String
id: String
phone: String
yearlySalary: double
bonus: double
monthlySalary: double
+ setLastName( String )
+ getLastName(): String
+ setFirstName( String )
+ getFirstName(): String
+ setId( String )
+ getId(): String
+ setPhone( String )
+ getPhone(): String
+ setYearlySalary( double )
+ getYearlySalary(): double
+ calcBonus( percent: double )
+ calcMonthlyPay()
+ inputAll(): boolean
+ toString(): String
+ equals(): boolean
Assignment Task(s)
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 “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. If you instantiate the Employee class into an object (e.g., person1), the main method is ignored.
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].calcBonus( 5 );
employee[0].calcMonthlyPay();
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())
{
employee[lp].calcMonthlyPay();
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
Employee.java
import java.util.Scanner;
public class Employee {
private String lastName;
private String firstName;
private String id;
private String phone;
private double yearlySalary;
private double bonus;
private double monthlySalary;
public Employee()
{
}
public Employee(String lastName, String firstName, String id, String phone,
double yearlySalary, double bonus, double monthlySalary) {
super();
this.lastName = lastName;
this.firstName = firstName;
this.id = id;
this.phone = phone;
this.yearlySalary = yearlySalary;
this.bonus = bonus;
this.monthlySalary = monthlySalary;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public double getYearlySalary() {
return yearlySalary;
}
public void setYearlySalary(double yearlySalary) {
this.yearlySalary = yearlySalary;
}
public double getBonus() {
return bonus;
}
public void setBonus(double bonus) {
this.bonus = bonus;
}
public double getMonthlySalary() {
return monthlySalary;
}
public void setMonthlySalary(double monthlySalary) {
this.monthlySalary = monthlySalary;
}
public void calcBonus(double percent)
{
bonus= yearlySalary*((double)percent/100);
}
void calcMonthlyPay()
{
monthlySalary=yearlySalary/12;
}
public boolean inputAll()
{
//Scanner object is used to get the inputs entered by the user
Scanner sc=new Scanner(System.in);
System.out.print("Enter Last Name :");
lastName=sc.nextLine();
if (lastName.isEmpty()) {
return false;
}
System.out.print("Enter First Name :");
firstName=sc.next();
System.out.print("Enter Employee Id :");
id=sc.next();
System.out.print("Enter Phone Number :");
phone=sc.next();
System.out.print("Enter Yearly Salary :$");
yearlySalary=sc.nextDouble();
System.out.print("Enter Yearly Bonus (%) :");
calcBonus(sc.nextInt());
return true;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((firstName == null) ? 0 : firstName.hashCode());
result = prime * result
+ ((lastName == null) ? 0 : lastName.hashCode());
return result;
}
public boolean equals(Employee other) {
if (firstName == null) {
if (other.firstName != null)
return false;
} else if (!firstName.equals(other.firstName))
return false;
if (lastName == null) {
if (other.lastName != null)
return false;
} else if (!lastName.equals(other.lastName))
return false;
return true;
}
@Override
public String toString() {
System.out.println("Employee Information");
System.out.println("Last Name=" + lastName);
System.out.println("First Name=" + firstName);
System.out.println("Id=" + id);
System.out.println("Phone=" + phone);
System.out.println("Yearly Salary=" + yearlySalary);
System.out.println("Bonus=" + bonus);
System.out.printf("Monthly Salary=%.2f " , monthlySalary);
return "";
}
}
_______________________
EmployeeTest.java
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].calcBonus( 5 );
employee[0].calcMonthlyPay();
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())
{
employee[lp].calcMonthlyPay();
System.out.println( employee[lp] );
}
else
{
System.out.println( "NO Information for Employee " + ( lp+1 ));
lp = MAX_EMPLOYEES;
}
}
}
}
_________________
Output:
Employee Information
Last Name=Murphy
First Name=Audie
Id=57831
Phone=619-555-1212
Yearly Salary=40000.0
Bonus=2000.0
Monthly Salary=3333.33
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 Information
Last Name=York
First Name=Alvin
Id=94834
Phone=619-555-9874
Yearly Salary=36000.0
Bonus=720.0
Monthly Salary=3000.00
Employee No. 3
Enter Last Name :
NO Information for Employee 3
___________Thank You
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.