fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Employee{
  9.  
  10. private int id;
  11. private String name;
  12. private String designation;
  13. private int ssnNo;
  14. private int age;
  15. private double salary;
  16. static int idCounter = 0;
  17.  
  18. public int getId(){
  19. return id;
  20. }
  21. public void setId(int id){
  22. this.id = id;
  23. }
  24.  
  25. public String getName(){
  26. return name;
  27. }
  28. public void setName(String name){
  29. this.name = name;
  30. }
  31.  
  32. public String getDesignation(){
  33. return designation;
  34. }
  35. public void setDesignation(String designation){
  36. this.designation = designation;
  37. }
  38.  
  39. public int getSsnNo(){
  40. return ssnNo;
  41. }
  42. public void setSsnNo(int ssnNo){
  43. this.ssnNo = ssnNo;
  44. }
  45.  
  46. public int getAge(){
  47. return age;
  48. }
  49. public void setAge(int age){
  50. this.age = age;
  51. }
  52.  
  53. public double getSalary(){
  54. return salary;
  55. }
  56. public void setSalary(double salary){
  57. this.salary = salary;
  58. }
  59.  
  60. public static int getIdCounter() {
  61. return idCounter;
  62. }
  63.  
  64. public Employee(String name, String designation, int ssnNo, int age, double salary){
  65. this.name = name;
  66. this.designation = designation;
  67. this.ssnNo = ssnNo;
  68. this.age = age;
  69. this.salary = salary;
  70. idCounter = idCounter + 1;
  71. this.id = idCounter;
  72. }
  73. }
  74.  
  75. class Ideone
  76. {
  77. public static void main (String[] args) throws java.lang.Exception
  78. {
  79. // your code goes here
  80. Employee employee1= new Employee("jirhehb","siarpha",35,70,776.0);
  81. System.out.println("Value of idCounter : " + Employee.getIdCounter());
  82. Employee employee2= new Employee("ycrdzsi","voivkqr",32,87,484.0);
  83. System.out.println("Value of idCounter : " + Employee.getIdCounter());
  84. Employee employee3= new Employee("txdxrzv","azpjbbb",4,63,369.0);
  85. System.out.println("Value of idCounter : " + Employee.getIdCounter());
  86. Employee employee4= new Employee("pefjukm","mctpbqe",36,0,951.0);
  87. System.out.println("Value of idCounter : " + Employee.getIdCounter());
  88. Employee employee5= new Employee("shbrzke","lpcnymz",51,86,181.0);
  89. System.out.println("Value of idCounter : " + Employee.getIdCounter());
  90. }
  91. }
Success #stdin #stdout 0.16s 55640KB
stdin
Standard input is empty
stdout
Value of idCounter : 1
Value of idCounter : 2
Value of idCounter : 3
Value of idCounter : 4
Value of idCounter : 5