Please answer this using Java and include all methods! This is the test class in
ID: 3691936 • Letter: P
Question
Please answer this using Java and include all methods!
This is the test class in text format so you can copy paste; if you need anything let me know please!
public class EmployeeTest
{
public static void main(String[] args)
{
Employee person1 = new Employee();
person1.setLastname( "Murphy" );
person1.setFirstname( "Audie" );
person1.setId( "57831" );
person1.setPhone( "619-555-1212" );
person1.setYearlySalary( 40000 );
person1.calcBonus( 5 );
person1.calcMonthlyPay();
System.out.println( person1 );
System.out.println();
Employee person2 = new Employee();
if ( person2.inputAll())
{
person2.calcBonus( 2 );
person2.calcMonthlyPay();
System.out.println( person2 );
System.out.println( person1.equals( person2 ));
}
else
{
System.out.println( "No EMployee 2" );
}
}
}
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 + setLastname String) + inputLastname): boolean -monthlyPay: double + getLastname ) String + BetFirstname String) + inputFirstname() void +getId String + setPhone( String) + inputPhonevoid + setId String) + inputId): void + getPhone ): String + etYearlySalary double) + getYearlySalary):double + inputYearSalary void + calculateBonus (percent: double) + getBonus): double + calcMonthlyPay() + getMonthlyPay): double + equals( Employee: boolean : Strin 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 "input" methods 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. The "inputLastname" method will return the boolean value true if a lastname was successfully entered and the value false if a blank was enteredExplanation / Answer
import java.util.*;
class Employee
{
private String lastname;
private String firstname;
private String id;
private String phone;
private double yearlySalary;
private double monthlyPay;
private double percent;
public void setLastname(String lastname)
{
this.lastname = lastname;
}
public String getLastname()
{
return lastname;
}
public boolean inputLastName()
{
System.out.println("Enter Last Name");
Scanner s = new Scanner(System.in);
String str = s.nextLine();
if(str == "")
return false;
else
{
setLastname(s.nextLine());
return true;
}
}
public void setFirstname(String firstname)
{
this.firstname = firstname;
}
public String getFirstname()
{
return firstname;
}
public void inputFirstName()
{
System.out.println("Enter First Name");
Scanner s = new Scanner(System.in);
setFirstname(s.nextLine());
}
public void setId(String id)
{
this.id = id;
}
public String getId()
{
return id;
}
public void inputId()
{
System.out.println("Enter the ID");
Scanner s = new Scanner(System.in);
setId(s.nextLine());
}
public void setPhone(String phone)
{
this.phone = phone;
}
public String getPhone()
{
return phone;
}
public void inputPhone()
{
System.out.println("Enter The Phone Number");
Scanner s = new Scanner(System.in);
setPhone(s.nextLine());
}
public void setYearlySalary(double yearlySalary)
{
this.yearlySalary = yearlySalary;
}
public double getYearlySalary()
{
return yearlySalary;
}
public void inputYearlySalary()
{
System.out.println("Enter The Yearly Salary");
Scanner s = new Scanner(System.in);
setYearlySalary(s.nextDouble());
}
public void calcBonus(double percent)
{
this.percent = percent;
}
public double calcMonthlyPay()
{
return (yearlySalary/12) + ((yearlySalary/12)*(percent/100));
}
public boolean equals(Employee e)
{
if(this.firstname.equals(e.firstname) && this.lastname.equals(e.lastname))
return true;
else
return false;
}
public String toString()
{
String str = "";
str += " LAST NAME: " + lastname + " FIRST NAME: " + firstname + " EMPLOYEE ID: " + id + " EMPLOYEE PHONE: " + phone + " EMPLOYEE SALARY: " + getYearlySalary() + " BONUS: " + percent + "% MONTHLY PAY: " + calcMonthlyPay();
return str;
}
public boolean inputAll()
{
if(inputLastName())
{
inputFirstName();
inputId();
inputPhone();
inputYearlySalary();
}
return false;
}
}
public class EmployeeTest
{
public static void main(String[] args)
{
Employee person1 = new Employee();
person1.setLastname( "Murphy" );
person1.setFirstname( "Audie" );
person1.setId( "57831" );
person1.setPhone( "619-555-1212" );
person1.setYearlySalary( 40000 );
person1.calcBonus( 5 );
person1.calcMonthlyPay();
System.out.println( person1 );
System.out.println();
Employee person2 = new Employee();
if ( person2.inputAll())
{
person2.calcBonus( 2 );
person2.calcMonthlyPay();
System.out.println( person2 );
System.out.println( person1.equals( person2 ));
}
else
{
System.out.println( "No EMployee 2" );
}
}
}