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: 3679940 • 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.45 Employee # is 900
Name= Wilma Salary= 60000.77 Employee # is 901
Name= Barny Salary= 70000.88 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

ObjectLab.java


class Employee {//Employee class

private String EmpName;//variable of empname, empno sal
private double EmpSalary;
private int EmpNum = 900;
private static int EmpNumCounter = 900;//counter for incrementing empid

public Employee(String Sname, double dSalary) {//constructor with arguments
EmpName = Sname;
EmpSalary = dSalary;
}
//getter and setter methods ofempname ,empno,salary
public String getEmpName() {
return EmpName;
}

public void setEmpName(String EmpName) {
this.EmpName = EmpName;
}

public int getEmpNum() {
return EmpNumCounter++;//incrmenting counter
}

public void setEmpNum(int EmpNum) {
this.EmpNum = EmpNum;
}

public double getEmpSalary() {
return EmpSalary;
}

public void setEmpSalary(double EmpSalary) {
this.EmpSalary = EmpSalary;
}
}

public class ObjectLab {//main program

public static void main(String[] args) {
Employee e1 = new Employee("Fred", 50000);//passing values to the constructor
e1.toString();//converting passed values in to string format
System.out.print(" Name :" + e1.getEmpName());
System.out.print(" Salary : " + e1.getEmpSalary());

System.out.println(" Employee # is " + e1.getEmpNum());

Employee e2 = new Employee("Wilma", 60000);//passing values to the constructor
e2.toString();//converting passed values in to string format
System.out.print(" Employee # is " + e2.getEmpName());
System.out.print("Salary :" + e2.getEmpSalary());
System.out.println(" Employee # is " + e2.getEmpNum());

Employee e3 = new Employee("Barny", 70000);//passing values to the constructor
e3.toString();//converting passed values in to string format
System.out.print(" Name : " + e3.getEmpName());
System.out.print(" Salary : " + e3.getEmpSalary());
System.out.print(" Employee # is " + e3.getEmpNum());


}
}

output

Name :Fred Salary : 50000.0 Employee # is 900
Employee # is WilmaSalary :60000.0 Employee # is 901
Name : Barny Salary : 70000.0 Employee # is 902

BUILD SUCCESSFUL (total time: 0 seconds)