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

Task: Write a class that models a few basic attributes and behaviors of an Emplo

ID: 670537 • Letter: T

Question

Task: Write a class that models a few basic attributes and behaviors of an Employee. The attributes required are last name, first name, id and salaryRate. These properties should be set and retrieved appropriately. You must also have 2 constructors for the class. The default which sets the names to empty String, id to -1 and salaryRate to 0.0. The second constructor should take values for all 4 attributes and set them appropriately.

You must also write a test class that tests each function that you write in the Employee class. Because you have 4 properties and 2 constructors, you should have 10 total functions to test. Each function must explicitly be called in your main program. Two objects must also be created with 1 using the default constructor and the other object using the constructor that takes 4 values.

You can use hard coded values in the main program to test your Employee class functions. If you want to use user input, that is fine as well, but not required (you would also not need to worry about invalid input (such as a user entering “five” instead of 5). Assume all user input will be without error if you choose to do user input).

Other programming requirements: All properties must be private. All set and get methods must be public and tested. Code will be examined during demo. Proper indenting is required in the code as well as documentation using comments.

Explanation / Answer

Class Employee

{

private string fname;

private string lname;

private int id;

private float sal_rate;

//Constructor 1 for default values;

Employee(string fname1, string lname1, int id1, float sal_rate1)

{

fname= fname1;

lname=lname1;

id= id1;

sal_rate= sal_rate1;

}

// Constructor 2 for different values

Employee(string fname2, string lname2, int id2, float sal_rate2)

{

fname=fname2;

lname= lname2;

id= id2;

sal_rate= sal_rate2;

}

// different setter and getter methods

public string getFname()

{

return fname;

}

public void setFname(string fname)

{

this.fname =fname;

}

public string getLname()

{

return Lname;

}

public void setLname(string lname)

{

this.lname= lname;

}

public int getId()

{

return id;

}

public void setId(int id)

{

this.id =id;

}

public float getSal_rate()

{

return sal_rate;

}

public void setSal_rate(float sal_rate)

{

this.sal_rate= sal_rate;

}

} // end of Employee class

public class EmployeeTest

{

public static void main(String [] args)

{

// create object of first constructor

Employee e1= new Employee(" ", " ", -1, 0.0);

System.out.println("Employee e1-fname:" +e1.getFname());

System.out.println("Employee e1-lname:" +e1.getLname());

System.out.println("Employee e1-id:" +e1.getId());

System.out.println("Employee e1-sal_rate:" +e1.getSal_rate());

// create object of second constructor. Here I am directly setting up the values , instead of this you can get the input from user also.

Employee e2= new Employee("Sam", "Dsouza",21, 5.7);

System.out.println("Employee e2-fname:" +e2.getFname());

System.out.println("Employee e2-lname:" +e2.getLname());

System.out.println("Employee e2-id:" +e2.getId());

System.out.println("Employee e2-sal_rate:" +e2.getSal_rate());

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote