Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

expand the Employee class to have methods of get employee name, get employee sal

ID: 3678532 • Letter: E

Question

expand the Employee class to have methods of get employee name, get employee salary, get employee ID.

Use a static variable to maintain employee ID

use my "main" program called "ObjectLab.java" but do not modify it. I will test with the base code.

Submit only the "Employee.java" file as a ZIP compression.

You must override the "toString()" method to return

Employee Name= <EmpName> Salary= <EmpSalary>

output should be this:

Name= Fred Salary= 50000.00 Employee # is 900
Name= Wilma Salary= 60000.00 Employee # is 901
Name= Barny Salary= 70000.00 Employee # is 902

File should be use:

/**
*
*
*
*
*/
public class ObjectLab
{
public static void main(String[] args)
{
Employee e1 = new Employee ("Fred", 50000);
System.out.print(e1.toString());
System.out.println(" Employee # is "+e1.getEmpNum());
  
Employee e2 = new Employee ("Wilma", 60000);
System.out.print(e2.toString());
System.out.println(" Employee # is "+e2.getEmpNum());
  
Employee e3 = new Employee ("Barny", 70000);
System.out.print(e3.toString());
System.out.println(" Employee # is "+e3.getEmpNum());
}
}

This is the Employee.java file

/**
*
*/
public class Employee
{
private String EmpName="";
private double EmpSalary=0.0;
private static int EmpNumCounter = 900;
private int EmpNum=0;
public Employee(String Sname, double dSalary)
{
  
}
  
public int getEmpNum()
{
return EmpNum;
}
  
}

Instructions

expand the Employee class to have methods of get employee name, get employee salary, get employee ID.

Use a static variable to maintain employee ID

use my "main" program called "ObjectLab.java" but do not modify it. I will test with the base code.

Submit only the "Employee.java" file as a ZIP compression.

You must override the "toString()" method to return

Employee Name= <EmpName> Salary= <EmpSalary>

output should be this:

Name= Fred Salary= 50000.00 Employee # is 900
Name= Wilma Salary= 60000.00 Employee # is 901
Name= Barny Salary= 70000.00 Employee # is 902

File should be use:

/**
*
*
*
*
*/
public class ObjectLab
{
public static void main(String[] args)
{
Employee e1 = new Employee ("Fred", 50000);
System.out.print(e1.toString());
System.out.println(" Employee # is "+e1.getEmpNum());
  
Employee e2 = new Employee ("Wilma", 60000);
System.out.print(e2.toString());
System.out.println(" Employee # is "+e2.getEmpNum());
  
Employee e3 = new Employee ("Barny", 70000);
System.out.print(e3.toString());
System.out.println(" Employee # is "+e3.getEmpNum());
}
}

This is the Employee.java file

/**
*
*/
public class Employee
{
private String EmpName="";
private double EmpSalary=0.0;
private static int EmpNumCounter = 900;
private int EmpNum=0;
public Employee(String Sname, double dSalary)
{
  
}
  
public int getEmpNum()
{
return EmpNum;
}
  
}

Explanation / Answer

Employee.java

public class Employee
{
   private String EmpName="";
   private double EmpSalary=0.0;
   private static int EmpNumCounter = 900;
   private int EmpNum=0;
  
   public Employee(String Sname, double dSalary)
   {
       this.EmpName = Sname;
       this.EmpSalary = dSalary;
       EmpNum = EmpNumCounter;
       EmpNumCounter++;
   }
   // getter
   public String getEmpName() {
       return EmpName;
   }
  
   public double getEmpSalary() {
       return EmpSalary;
   }
  
   public int getEmpNum() {
       return EmpNum;
   }
  
   @Override
   public String toString() {
      
       return "Name="+EmpName+" Salary="+String.format("%.2f", EmpSalary);
   }
}

//////////////////////////////////////////////////

ObjectLab.java

public class ObjectLab
{
public static void main(String[] args)
{
    Employee e1 = new Employee ("Fred", 50000);
    System.out.print(e1.toString());
    System.out.println(" Employee # is "+e1.getEmpNum());
  
    Employee e2 = new Employee ("Wilma", 60000);
    System.out.print(e2.toString());
    System.out.println(" Employee # is "+e2.getEmpNum());
  
    Employee e3 = new Employee ("Barny", 70000);
    System.out.print(e3.toString());  
    System.out.println(" Employee # is "+e3.getEmpNum());
}
}


/*

Output:

Name=Fred Salary=50000.00 Employee # is 900
Name=Wilma Salary=60000.00 Employee # is 901
Name=Barny Salary=70000.00 Employee # is 902

*/