Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Society
- {
- private ArrayList<Member> myMembers;
- private Member member;
- private String societyName;
- private boolean feesPaid;
- public Society(String society)
- {
- myMembers = new ArrayList<Member>();
- this.societyName = society;
- }
- public String getSocietyName()
- {
- return societyName;
- }
- public void join(Member member)
- {
- myMembers.add(member);
- }
- public void showMember(int listPosition)
- {
- Member member;
- if( listPosition < myMembers.size() )
- {
- member = myMembers.get(listPosition);
- System.out.println("Position " + listPosition + ": " + member);
- }
- }
- public void joinedInMonth(int joined) {
- if (joined > 12 || joined < 1) {
- System.out.println("Invalid number. Please enter a number from 1 - 12.");
- }
- long joinedMonth = myMembers.stream().filter(m -> m.getMonth() == joined).count();
- System.out.printf("%d members have joined this society on month %d%n", joinedMonth, joined);
- }
- public int numberOfMembers()
- {
- return myMembers.size();
- }
- public void printDetails()
- {
- for (Member m : myMembers) {
- System.out.println("Society Name: " + societyName);
- System.out.println(m.toString());
- System.out.println("--------------------------");
- }
- }
- public void removeMembers(int month, int year) {
- myMembers.removeIf(m -> m.getYear() == year && m.getMonth() == month);
- }
- public void payFees(Member member)
- {
- if (member.isFeesPaid()) {
- System.out.println("Fees has been paid");
- return;
- }
- }
- }
- public class Member
- {
- private int month;
- private int year;
- private String name;
- /*private Society society;*/
- private List<Society> societies;
- private boolean feesPaid;
- public Member(String name, int month, int year /*Society society*/)
- {
- this.name = name;
- this.month = month;
- this.year = year;
- this.societies = new ArrayList<>();
- }
- public void joinSociety(Society society)
- {
- societies.add(society);
- }
- public boolean isFeesPaid() {
- return feesPaid;
- }
- public int getYear()
- {
- return year;
- }
- public int getMonth()
- {
- return month;
- }
- public String getName()
- {
- return name;
- }
- public String toString()
- {
- return "Name: " + name + ", Month Joined: " + month + ", Year Joined: " + year;
- }
Add Comment
Please, Sign In to add comment