+ 2

Create two Employee objects and display each object’s yearly salary.

Then give each Employee a 10 percent raise and display each Employee’s yearly salary again.

25th Sep 2017, 5:48 PM
Zusakhe
3 Answers
+ 1
Class Employee: public class Employee { private String firstName; private String lastName; private double monthlySalary; public Employee(String f, String l, double m){ firstName = f; lastName = l; if(m < 0){ // you can also use setMonthlySalary(m) monthlySalary =0; } else monthlySalary = m; } public String getFirstName() { return firstName; } public void setFirstName(String fname) { firstName = fname; } public void setLastName(String lname) { lastName = lname; } public double getMonthlySalary() { return monthlySalary; } public void setMonthlySalary(double m) { if(m < 0){ monthlySalary =0; } else monthlySalary = m; } } Class EmployeeTest: import java.util.Scanner; public class EmployeeTest { public static void main(String[] args){ Scanner S = new Scanner(System.in); System.out.println("Enter the first name: "); String fname = S.next(); System.out.println("Enter the last name: "); String lname = S.next(); System.out.println("Enter the Salary: "); double sal = S.nextDouble(); Employee e =new Employee(fname,lname ,sal ); System.out.println("the yearly salary of "+e.getFirstName()+" " +e.getLastName()+" :"); System.out.println(e.getMonthlySalary()*12); double newsalary= e.getMonthlySalary()*0.1+e.getMonthlySalary(); e.setMonthlySalary(newsalary); System.out.println("the new yearly salary of "+ e.getFirstName()+" "+e.getLastName()+" :"); System.out.println(e.getMonthlySalary()*12); e.getMonthlySalary(); } }
26th Sep 2017, 9:40 AM
Zusakhe
0
Full answer
29th Oct 2024, 4:28 PM
Ruth Nkiru Nwoke