Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.42 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class Main{
  4. public static void main(String[]args){
  5. Employee e=new Employee();
  6. e.input();
  7. CalculateGrossSalary c=new CalculateGrossSalary(e);
  8. c.showInfo();
  9. }
  10. }
  11. class Employee{
  12. static Scanner input=new Scanner(System.in);
  13. private int code;
  14. private double salary,da,hra;
  15. private String name;
  16. public int getCode() {
  17. return code;
  18. }
  19. public double getSalary() {
  20. return salary;
  21. }
  22. public String getName() {
  23. return name;
  24. }
  25. public double getDA(){
  26. if(this.salary<=10000){
  27. this.da=this.salary*0.8;
  28. }
  29. else if(this.salary<=20000){
  30. this.da=this.salary*0.9;
  31. }
  32. else{
  33. this.da=this.salary*0.95;
  34. }
  35. return this.da;
  36. }
  37. public double getHRA(){
  38. if(this.salary<=10000){
  39. this.hra=this.salary*0.2;
  40. }
  41. else if(this.salary<=20000){
  42. this.hra=this.salary*0.25;
  43. }
  44. else{
  45. this.hra=this.salary*0.3;
  46. }
  47. return this.hra;
  48. }
  49. public void input(){
  50. System.out.print("Enter the employee code:");
  51. this.code=input.nextInt();
  52. System.out.print("Enter name:");
  53. this.name=input.next();
  54. System.out.print("Enter salary:");
  55. this.salary=input.nextDouble();
  56. }
  57. }
  58. class CalculateGrossSalary{
  59. public Employee e;
  60. public CalculateGrossSalary(Employee e){
  61. this.e=e;
  62. }
  63. public void showInfo(){
  64. System.out.println("Code:"+e.getCode());
  65. System.out.println("Name:"+e.getName());
  66. System.out.println("Salary:"+e.getSalary());
  67. double gs=e.getSalary()+this.e.getHRA()+this.e.getDA();
  68. System.out.println("Gross Salary:"+gs);
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement