Here is the requirements:
create a class include first name, last name, and monthly salary variables.
Create a set and get method for each instance variable.
What is the set method for(I read the book several times)? I don't quite get how to use it. How to create a set method for those three variable? When I executive the Employeetest, the year salary became 660.00000. How can I just limit it to 2 decimals?
Thank you so much.
class Employee
{
private String firstName;
private String lastName;
private double monthlySalary;
public Employee( String f, String l, double m )
{
firstName = f;
lastName = l;
monthlySalary = m;
}
public String getFirstName()
{
return firstName;
}
public String getLastName()
{
return lastName;
}
public double getMonthlySalary()
{
return monthlySalary;
}
@Override
public String toString()
{
return getFirstName() + getLastName();
}
}
public class EmployeeTest
{
public static void main(String[] args)
{
Employee employee1 = new Employee("Eric", "Jackson", 100);
Employee employee2 = new Employee("Zerk", "Wiz", 50);
System.out.printf("%s %s \n", employee1.getFirstName(), employee1.getLastName() );
System.out.printf( "yearly salary is %f \n", employee1.getMonthlySalary()*12);
System.out.printf("After 10 percent raising, the year salary is %f \n",employee1.getMonthlySalary()*12 * 1.1);
System.out.printf("%s %s \n", employee2.getFirstName(), employee2.getLastName() );
System.out.printf("yearly salary is %f \n", employee2.getMonthlySalary()*12);
System.out.printf("After 10 percent raising, the year salary is %f",employee2.getMonthlySalary()*12 * 1.1);
}