Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.39 KB | None | 0 0
  1. import java.util.*;
  2. /**
  3. * Ten program sprawdza działanie klasy Employee.
  4. * @version 1.11 2004-02-19
  5. * @author Cay Horstmann
  6. */
  7. public class EmployeeTest
  8. {
  9. public static void main(String[] args)
  10. {
  11. // Wstawienie trzech obiektów pracowników do tablicy staff.
  12. Employee[] staff = new Employee[3];
  13. staff[0] = new Employee("Jarosław Rybiński", 75000, 1987, 12, 15);
  14. staff[1] = new Employee("Katarzyna Remiszewska ", 50000, 1989, 10, 1);
  15. staff[2] = new Employee("Krystyna Kuczyńska ", 40000, 1990, 3, 15);
  16. // Zwiększenie pensji wszystkich pracowników o 5%.
  17. for (Employee e : staff)
  18. e.raiseSalary(5);
  19. // Drukowanie informacji o wszystkich obiektach klasy Employee.
  20. for (Employee e : staff)
  21. System.out.println("name=" + e.getName() + ",salary=" + e.getSalary()
  22. + ",hireDay="
  23. + e.getHireDay());
  24. }
  25. }
  26. class Employee
  27. {
  28. private String name;
  29. private double salary;
  30. private Date hireDay;
  31. public Employee(String n, double s, int year, int month, int day)
  32.  
  33. {
  34. name = n;
  35. salary = s;
  36. GregorianCalendar calendar = new GregorianCalendar(year, month - 1, day);
  37. // W klasie GregorianCalendar styczeń ma numer 0.
  38. hireDay = calendar.getTime();
  39. }
  40. public String getName()
  41. {
  42. return name;
  43. }
  44. public double getSalary()
  45. {
  46. return salary;
  47. }
  48. public Date getHireDay()
  49. {
  50. return hireDay;
  51. }
  52. public void raiseSalary(double byPercent)
  53. {
  54. double raise = salary * byPercent / 100;
  55. salary += raise;
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement