1. import java.util.Scanner;
    2. interface Employee{
    3. int getSalary();
    4. }
    5. class Programmer implements Employee{
    6. int salary ;
    7. Programmer(){
    8. salary = 5000;
    9. }
    10. @Override
    11. public int getSalary(){
    12. return salary;
    13. }
    14. }
    15. class SeniorProgrammer extends Programmer{
    16. SeniorProgrammer(){
    17. super();
    18. salary = 5000;
    19. }
    20. @Override
    21. public int getSalary(){
    22. return salary + 5000;
    23. }
    24. }
    25. class Manager extends SeniorProgrammer{
    26. Manager(){
    27. super();
    28. this.salary += 5000;
    29. }
    30. @Override
    31. public int getSalary(){
    32. return salary + 5000 + 5000;
    33. }
    34. }
    35. class ProgrammerFactory{
    36. public Programmer makeProgrammer(String pos){
    37. if(pos.equals("Programmer")){
    38. return new Programmer();
    39. }else if(pos.equals("SeniorProgrammer")){
    40. return new SeniorProgrammer();
    41. }else if(pos.equals("Manager")){
    42. return new Manager();
    43. }else {
    44. return null;
    45. }
    46. }
    47. }
    48. public class factory{
    49. public static void main(String[] args){
    50. ProgrammerFactory factory = new ProgrammerFactory();
    51. Employee Programmer = factory.makeProgrammer("Programmer");
    52. Employee SeniorProgrammerProgrammer = factory.makeProgrammer("SeniorProgrammer");
    53. Employee Manager = factory.makeProgrammer("Manager");
    54. Manager.getSalary();
    55. Programmer.getSalary();
    56. SeniorProgrammer.getSalary();
    57. }
    58. }