In: Computer Science
1) Create a class called Employee that includes three instance variables — a first name (type String), a last name (type String) and a monthly salary (double). Provide a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its value.
2)Create an app named EmployeeLinkedList that stores a collection of Employee objects in a LinkedList<Employee>. Test the app by creating five Employee objects and adding the Employees to the LinkedList<Employee> , then re-access the LinkedList<Employee> to display each Employee object’s yearly salary. Then give each Employee a 10% raise and display each Employee’s yearly salary again.
Provide one java program with two different classes. the program should be working and display output. need it ASAP
import java.util.LinkedList; class Employee { private String first, last; private double salary; public Employee(String first, String last, double salary) { this.first = first; this.last = last; setSalary(salary); } public String getFirst() { return first; } public void setFirst(String first) { this.first = first; } public String getLast() { return last; } public void setLast(String last) { this.last = last; } public double getSalary() { return salary; } public void setSalary(double salary) { if (salary >= 0) this.salary = salary; } @Override public String toString() { return first + ", " + last + " Sal: $" + salary; } public void raiseSalary(double times) { salary += salary * times; } } public class EmployeeLinkedList { public static void main(String[] args) { LinkedList<Employee> empList = new LinkedList<>(); empList.add(new Employee("EmpF1", "EmpL1", 10000)); empList.add(new Employee("EmpF2", "EmpL2", 20000)); empList.add(new Employee("EmpF3", "EmpL3", 14000)); empList.add(new Employee("EmpF4", "EmpL4", 16000)); empList.add(new Employee("EmpF5", "EmpL5", 8000)); for(Employee e: empList) { System.out.println(e); } // give raise. System.out.println("\nAfter raising salary"); for(Employee e: empList) { e.raiseSalary(0.1); System.out.println(e); } } }
************************************************** Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.
Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.