Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. import java.sql.Date;
  2.  
  3. public class RunWeek5 {
  4. public static void main(String[] args) {
  5.  
  6. Student s1 = new Student("Shamil", "Arslanov", Date.valueOf("2000-02-17"));
  7. Student s2 = new Student("Marya", "Sayanova", Date.valueOf("2001-07-01"));
  8. Student_Girl g1 = new Student_Girl("Masha", "Xyz", Date.valueOf("1999-06-06"), true, true);
  9.  
  10. Group data = new Group();
  11. data.addStudent(s2);
  12. data.addStudent(s1);
  13. data.addStudent(g1);
  14. }
  15.  
  16. }
  17.  
  18. public class Person {
  19.  
  20. protected String firstName;
  21. protected String lastName;
  22. private static int ID = 1;
  23. protected int personId;
  24.  
  25. public Person(String firstName, String lastName) {
  26. this.firstName = firstName;
  27. this.lastName = lastName;
  28. ++ID;
  29. this.personId = ID;
  30. }
  31.  
  32. public Person() {
  33. this.firstName = "Null";
  34. this.lastName = "Null";
  35. this.personId = ++ID;
  36. }
  37.  
  38. public String getFullName() {
  39. return firstName + " " + lastName;
  40. }
  41. public String getFullName(boolean reverse) {
  42. if (reverse) return lastName + " " + firstName;
  43. else return getFullName();
  44. }
  45.  
  46. @Override
  47. public String toString() {
  48. return "Person{" +
  49. "firstName='" + firstName + '\'' +
  50. ", lastName='" + lastName + '\'' +
  51. ", personId=" + personId +
  52. '}';
  53. }
  54. }
  55.  
  56. import java.sql.Date;
  57.  
  58.  
  59. public class Student extends Person {
  60. private Date dateOfBirth;
  61.  
  62.  
  63. public Student(String firstName, String lastName, Date dateOfBirth) {
  64. super(firstName, lastName);
  65. this.dateOfBirth = dateOfBirth;
  66. }
  67.  
  68. @Override
  69. public String toString() {
  70. return "Student{" +
  71. "dateOfBirth=" + dateOfBirth +
  72. ", firstName='" + firstName + '\'' +
  73. ", lastName='" + lastName + '\'' +
  74. ", personId=" + personId +
  75. '}';
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement