Please answer this using java and include all methods! This is the test class in
ID: 3692452 • 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" );
}
}
}
Explanation / Answer
Hi, I have implemented all methods except bonus related methods. There is no explanation about bonus - how to calculate, where store and also about calculateMonthlySalary() method. So, please implement these 3 methods.
Rest all i did. You can test with yout Test class
import java.util.Scanner;
public class Employee{
private String lastName;
private String firstName;
private String id;
private String phone;
private double yearlySalary;
private double monthlyPay;
public static Scanner sc = new Scanner(System.in);
public String getLastName() {
return lastName;
}
public String getFirstName() {
return firstName;
}
public String getId() {
return id;
}
public String getPhone() {
return phone;
}
public double getYearlySalary() {
return yearlySalary;
}
public double getMonthlyPay() {
return monthlyPay;
}
public static Scanner getSc() {
return sc;
}
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 setMonthlyPay(double monthlyPay) {
this.monthlyPay = monthlyPay;
}
public static void setSc(Scanner sc) {
Employee.sc = sc;
}
public boolean inputLastname(){
System.out.print("Enter lastname: ");
lastName = sc.next();
if(lastName.trim().equals(""))
return false;
return true;
}
public void inputFirstname(){
System.out.print("Enter firstName: ");
firstName = sc.next();
}
public void inputId(){
System.out.print("Enter id: ");
id = sc.next();
}
public void inputPhone(){
System.out.print("Enter phone: ");
phone = sc.next();
}
public void inputYearlySalary(){
System.out.print("Enter yearly salary: ");
yearlySalary = sc.nextDouble();
}
public double calculateBonus(double percentage){
return 0; //TODO
}
public double getBonus(){
return 0;//TODO
}
public void calculateMonthlyPay(){
//TODO
}
@Override
public boolean equals(Object obj) {
Employee o = (Employee)obj;
if(this.firstName.equalsIgnoreCase(o.firstName)
&& this.lastName.equalsIgnoreCase(o.lastName))
return true;
return false;
}
@Override
public String toString() {
return "LAST NAME: "+lastName+
" FIRST NAME: "+firstName+
" EMPLOYEE ID: "+id+
" EMPLOYEE PHONE: "+phone+
" EMPLOYEE SALARY: "+yearlySalary+
" BONUS: "+getBonus()+
" MONTHLY PAY: "+getMonthlyPay();
}
public boolean inputAll(){
if(!inputLastname())
return false;
inputFirstname();
inputId();
inputPhone();
inputYearlySalary();
return true;
}