هذا السؤال عشان ماتخربطون ..+)
Q4) Write a java program that calculates the net salary for the employees in a company. The
program contains a class called Employee that has the following data members:
a) The employee name (type String)
b) The year of employment (type int)
c) The assurance type: an integer number (1, 2, or 3) indicating the type of the assurance.
Define a constructer that initializes the three instance variables. Provide a set and get method for
each instance variable.
Define a method called getExperinceYears( ) that calculates and returns the working experience
years for the employee.
Define a method called netSalary( ) that calculates and returns the net salary as follows:
1- Calculates the monthly basic salary as follows:
a) If the experience years are 10 years or more, the basic salary = 1500 + 15*experience years
b) If the experience years are less than 10 years, the basic salary = 1000 + 10*experience years
2- Calculates the assurance as follows:
a) assurance = 20 (if assurance type is 1)
b) assurance = 15 (if assurance type is 2)
c) assurance = 10 (if assurance type is 3)
3- Calculate the net salary = basic salary – assurance
Creates two Employee objects and display each object’s net salary. Test your class with the
following employees’ information:
Employee("Abrar",1998,3)
Employee("Sara", 2008,1)
.................................................................................................................................................
public class Employee {
private String name;
private int year;
private int assurance;
int ey;
public Employee(String n,int y,int a){
name = n;
year = y;
assurance = a;
}
public void setname (String n){
name = n;
}
public void setyear (int y){
if (year > 0)
year = y;
}
public void setassurance (int a){
if( assurance > 0)
assurance = a;
}
public String getname(){
return name;
}
public int getyear (){
return year;
}
public int getassurance (){
return assurance;
}
public int getExperinceYears( ){
ey = year - 2010;
return ey;
}
public double netSalary(){
double bs;
if ( ey >= 10 )
bs = 1500 + 15 * ey;
else
bs = 1000 + 10 * ey;
if (assurance == 1)
assurance = 20;
if (assurance == 2)
assurance = 15;
if (assurance == 3)
assurance = 10;
double netsalary = bs - assurance;
return netsalary;
}
}public class Employeetest {
public static void main(String[] args){
Employee em1 = new Employee("Abrar",1998,3);
Employee em2 = new Employee("Sara",2008,1);
em1.setname ("Abrar");
em1.setyear(1998);
em1.setassurance(3);
em1.getyear ();
em1.getExperinceYears();
em1. getassurance ();
System.out.printf("The net Salary for employee %s is %.3f kD",em1.getname(),em1.netSalary() );
em2.setname ("sara");
em2.setyear(2008);
em2.setassurance(1);
em2.getyear ();
em2.getExperinceYears();
em2.getassurance ();
System.out.print("\nThe net Salary for employee ");
System.out.print(em2.getname());
System.out.print(" is ");
System.out.print(em2.netSalary());
System.out.print(" kD");output
The net Salary for employee Abrar is 870.000 kD
The net Salary for employee sara is 960.0 kD
المفروض الأرقام تكون مثل أرقام الدكتور اللي بالoutput
The net Salary for employee Abrar is 1650.000 KD
The net Salary for employee Sara is 1000.000 KD
صح جذي ولا أنا مسويه غلط وآنا مادري!!!