Create a class with following
specifications.
Class Emp
empId int
empName string
designation string
basic
double
hra
double readOnly
Methods
printDET()
calculateHRA()
printDET() methods will show details
of the EMP.
calculateHRA()
method will calculate HRA based on basic.
There will 3 designations supported
by the application.
If designation is “Manager”
- HRA will be 10% of BASIC
if designation is “Officer”
- HRA will be 12% of BASIC
if category is “CLERK” - HRA will be 5% of BASIC
Have constructor to which you will pass, empId,
designation, basic and price.
And checks whether the BASIC is
less than 500 or not. If it is less than 500 raise a custom Exception as given
below
Create LowSalException class with
proper user message to handle BASIC less than 500.
package emp3;
class Emp {
int empid;
String Name;
String designation;
double basic;
double hra;
int getEmpid() {
return empid;
}
void setEmpid(int empid) {
this.empid = empid;
}
String getName() {
return Name;
}
void setName(String name) {
Name = name;
}
String getDesignation() {
return designation;
}
void setDesignation(String designation) {
this.designation = designation;
}
double getBasic() {
if (basic < 500) {
try {
throw new LowSalException();
} catch (LowSalException e) {
// TODO Auto-generated catch block
// e.printStackTrace();
System.out.println(e);
}
}
return basic;
}
void setBasic(double basic) {
this.basic = basic;
}
public Emp() {
this.empid = 1;
Name = "Abhi";
this.designation = "SOFT ENGG";
this.basic = 300;
}
public Emp(int empid, String name, String designation, double basic) {
this.empid = empid;
Name = name;
this.designation = designation;
this.basic = basic;
}
public void printDET() {
System.out.println("Id Of Employye :" + empid
+ "\n Name of Employee is :" + Name
+ "\n Designation Of Employee is:" + designation
+ "\nSalary Of Employee :" + basic);
}
public void calculateHRA() {
if (designation == "Manager") {
hra = basic * 0.1;
System.out.println("HRA OF MANAGER : " + hra);
}
else if (designation == "Officer") {
hra = basic * 0.12;
System.out.println("HRA OF OFFICER : " + hra);
}
else {
hra = basic * 0.05;
System.out.println("HRA OF CLEARK : " + hra);
}
}
public static void main(String[] args) {
Emp e = new Emp();
e.getBasic();
e.printDET();
System.out.println();
Emp e1 = new Emp(2, "Amol", "Manager", 50000);
e1.printDET();
e1.calculateHRA();
System.out.println();
Emp e2=new Emp(3,"Suraj","officer",10000);
e2.printDET();
e2.calculateHRA();
System.out.println();
System.out.println();
Emp e3=new Emp(4,"Sushant","cleark",15000);
e3.printDET();
e3.calculateHRA();
}
}
package emp3;
import java.util.Arrays;
public class LowSalException extends Exception {
@Override
public String toString() {
return "Opps There is Low Balance Than 500 Reppues";
}
}
No comments:
Post a Comment