Guest User

Untitled

a guest
Jul 16th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. public class Society
  2. {
  3. private ArrayList<Member> myMembers;
  4. private Member member;
  5. private String societyName;
  6. private boolean feesPaid;
  7.  
  8.  
  9. public Society(String society)
  10. {
  11. myMembers = new ArrayList<Member>();
  12. this.societyName = society;
  13. }
  14.  
  15. public String getSocietyName()
  16. {
  17. return societyName;
  18. }
  19.  
  20. public void join(Member member)
  21. {
  22. myMembers.add(member);
  23. }
  24.  
  25. public void showMember(int listPosition)
  26. {
  27. Member member;
  28. if( listPosition < myMembers.size() )
  29. {
  30. member = myMembers.get(listPosition);
  31. System.out.println("Position " + listPosition + ": " + member);
  32. }
  33. }
  34.  
  35. public void joinedInMonth(int joined) {
  36. if (joined > 12 || joined < 1) {
  37. System.out.println("Invalid number. Please enter a number from 1 - 12.");
  38. }
  39. long joinedMonth = myMembers.stream().filter(m -> m.getMonth() == joined).count();
  40. System.out.printf("%d members have joined this society on month %d%n", joinedMonth, joined);
  41.  
  42. }
  43.  
  44. public int numberOfMembers()
  45. {
  46. return myMembers.size();
  47. }
  48.  
  49. public void printDetails()
  50. {
  51. for (Member m : myMembers) {
  52. System.out.println("Society Name: " + societyName);
  53. System.out.println(m.toString());
  54. System.out.println("--------------------------");
  55. }
  56.  
  57. }
  58.  
  59. public void removeMembers(int month, int year) {
  60. myMembers.removeIf(m -> m.getYear() == year && m.getMonth() == month);
  61. }
  62.  
  63. public void payFees(Member member)
  64. {
  65. if (member.isFeesPaid()) {
  66. System.out.println("Fees has been paid");
  67. return;
  68. }
  69. }
  70. }
  71.  
  72. public class Member
  73. {
  74.  
  75. private int month;
  76. private int year;
  77. private String name;
  78. /*private Society society;*/
  79. private List<Society> societies;
  80. private boolean feesPaid;
  81. public Member(String name, int month, int year /*Society society*/)
  82. {
  83. this.name = name;
  84. this.month = month;
  85. this.year = year;
  86. this.societies = new ArrayList<>();
  87. }
  88.  
  89. public void joinSociety(Society society)
  90. {
  91. societies.add(society);
  92. }
  93.  
  94. public boolean isFeesPaid() {
  95. return feesPaid;
  96. }
  97.  
  98. public int getYear()
  99. {
  100. return year;
  101. }
  102.  
  103. public int getMonth()
  104. {
  105. return month;
  106. }
  107.  
  108. public String getName()
  109. {
  110. return name;
  111. }
  112.  
  113. public String toString()
  114. {
  115. return "Name: " + name + ", Month Joined: " + month + ", Year Joined: " + year;
  116. }
Add Comment
Please, Sign In to add comment