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

7.12 (Emp1oyee Class) Create a class called Employee that includes three instanc

ID: 3725578 • Letter: 7

Question

7.12 (Emp1oyee Class) Create a class called Employee that includes three instance varia first name (ype String), a last name (oype String) and a monthly salary (double). Provide a- structor that initializes the three instance variables. Provide a set and a get method for cach i variable. If the monthly salary is not positive, do not set its value. Write a test app named Emi eeTest that demonstrates class Employee's capabilities. Create two Employee objects and display cach object's yearly salary. Then give each Employee a 10% raise and display each Employee's yearly gain.

Explanation / Answer

Note : Could you please check the output .If you required any changes Just intimate.I will modify it.Thank You.

________________

Employee.java

public class Employee {
//Declaring instance variables
private String firstName;
private String lastName;
private double salary;
//Parameterized constructor
public Employee(String firstName, String lastName, double salary) {
this.firstName = firstName;
this.lastName = lastName;
setSalary(salary);
}
//getters and setters
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
if (salary < 0)
this.salary = 0.0;
else
this.salary = salary;
}

}

__________________

EmployeeTest.java

import java.util.Scanner;

public class EmployeeTest {

public static void main(String[] args) {
String firstname, lastname;
double sal;

/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
Scanner sc = new Scanner(System.in);

System.out.println("Employee#1:");
//Getting the input entered by the user
System.out.print("Enter the firstname :");
firstname = sc.next();

System.out.print("Enter the lastname :");
lastname = sc.next();

System.out.print("Enter Salary :$");
sal = sc.nextDouble();

//Creating an instance of Employee class
Employee e1 = new Employee(firstname, lastname, sal);

System.out.println("Employee#2:");
//Getting the input entered by the user
System.out.print("Enter the firstname :");
firstname = sc.next();

System.out.print("Enter the lastname :");
lastname = sc.next();

System.out.print("Enter Salary :$");
sal = sc.nextDouble();

//Creating an instance of Employee class
Employee e2 = new Employee(firstname, lastname, sal);
//Displaying the Employee Yearly Salary
System.out.println("Employee#1 Yearly salary :$" + 12 * e1.getSalary());
System.out.println("Employee#2 Yearly salary :$" + 12 * e2.getSalary());

//Raising the 10% salary
e1.setSalary(e1.getSalary() + e1.getSalary() * 0.10);
e2.setSalary(e2.getSalary() + e2.getSalary() * 0.10);
//Displaying the Employee Yearly Salary
System.out.println("___Displaying the Employees Salary after 10% raise __");
System.out.println("Employee#1 Yearly salary :$" + 12 * e1.getSalary());
System.out.println("Employee#2 Yearly salary :$" + 12 * e2.getSalary());

}

}

___________________

Output:

Employee#1:
Enter the firstname :Kane
Enter the lastname :Williams
Enter Salary :$45000.00
Employee#2:
Enter the firstname :Sachin
Enter the lastname :Tendulkar
Enter Salary :$60000.00
Employee#1 Yearly salary :$540000.0
Employee#2 Yearly salary :$720000.0
___Displaying the Employees Salary after 10% raise __
Employee#1 Yearly salary :$594000.0
Employee#2 Yearly salary :$792000.0

__________________Thank You

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