Question

5: Assume that a Sports Club at the University wishes to store details about its members. Design and implement a Java application to support this requirement. The application should be able to print out and manage information about the members of the club. The following guidelines should be used to construct the applicatiorn a: A Java class, called Member, should be defined to store and manage member details. The class should include methods for updating member details and querying their registration status i.e. are they fully paid up members of the club Each member of the club should also have a unique membership id number, this number is automatically assigned when the member object is created. The Member class should implement the Comparable interface and use the membership id number to define the natural order for these objects 10 MARKS b: Define another Java class, called SportsClub, that will be used to manage club membership and access details about individual members. Member objects added to the SportsClub should be stored using a suitable collection object. Member objects should be sorted by their id number as they are added to the collection. SportsClub should include methods for adding new members removing members and returning a list of current members. 10 MARKS c: Write a short driver program, in a class called ClubManager, that creates an instance of SportsClub and uses its methods to add, lookup and remove club members. The program should also be able to save the full application state on exit, using Object Serialization, and load up the saved state at startup

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Done. Have a look and in case of any doubt leave a comment.

/////////////////////////////////////Member.java/////////////////////////////////////

package com.java.sportsClub;

import java.util.ArrayList;

import java.util.Collections;

//Member class which implements Comparable interface and implement CompareTo using membership id.

public class Member implements Comparable<Member> {

private int membershipId;

private boolean isFullyPaid;

private String name;

private static ArrayList<Integer> numbers = new ArrayList<>();

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getMembershipId() {

return membershipId;

}

public void setMembershipId(int membershipId) {

this.membershipId = membershipId;

}

public boolean isFullyPaid() {

return isFullyPaid;

}

public void setFullyPaid(boolean isFullyPaid) {

this.isFullyPaid = isFullyPaid;

}

// create a arraylist of integers from 1-100 for generating random nymbers later

static {

for (int i = 0; i < 100; i++) {

numbers.add(i + 1);

}

}

@Override

// It should return a negative integer, if the current

// object is less than the passed one, and positive integer if

// greater than, and 0 if equal.

public int compareTo(Member arg0) {

// TODO Auto-generated method stub

if (this.membershipId == arg0.membershipId) {

return 0;

}

if (this.membershipId < arg0.membershipId) {

return -1;

} else {

return 1;

}

}

// Constructor with two parameters and assign membership id automatically

public Member(String name, boolean isFullyPaid) {

this.name = name;

this.isFullyPaid = isFullyPaid;

this.membershipId = generateRandomNumber();

}

// generate random number

private int generateRandomNumber() {

Collections.shuffle(numbers);

// System.out.println("Elem : " + numbers.get(0));

return numbers.get(0);

}

@Override

// print all information about Members i.e. name, id and isFullyPaid or not

public String toString() {

return "Name=" + name + ", membershipId=" + membershipId + ", isFullyPaid=" + isFullyPaid;

}

}

///////////////////////////End Member.java//////////////////////////////////////////////////////

////////////////////////////////SportsClub.java//////////////////////////////////////

package com.java.sportsClub;

import java.util.ArrayList;

import java.util.Collections;

//Class that maintains list of members. Manage them

public class SportsClub {

// list of members

private ArrayList<Member> members = new ArrayList<>();

// add new member and sort them

public void addMemember(Member member) {

this.members.add(member);

Collections.sort(members);

}

// return list of all member

public ArrayList<Member> getMembers() {

return this.members;

}

// If the parameter given is in the list them remove from list

public void removeMember(Member m) {

if (members.contains(m)) {

members.remove(m);

System.out.println("Removed element " + m);

return;

}

}

// search for the paramter member. Return member if found . Null otherwise

public Member findMember(Member m) {

for (int i = 0; i < members.size(); i++) {

if (members.get(i).equals(m)) {

return members.get(i);

}

}

return null;

}

}

////////////////////////////////End SportsClub.java//////////////////////////////////////

///////////////////////////ClubManager.java/////////////////////////////////////////

package com.java.sportsClub;

//Driver class to test SportsCLub and Member class

public class ClubManager {

public static void main(String args[]) {

// create instance of SportsClub

SportsClub club = new SportsClub();

// add memebers to club

Member member1 = new Member("Member1", false);

Member member2 = new Member("Member2", true);

Member member3 = new Member("Member3", false);

Member member4 = new Member("Member4", true);

club.addMemember(member1);

club.addMemember(member2);

club.addMemember(member3);

club.addMemember(member4);

// Print list of all the members

for (int i = 0; i < club.getMembers().size(); i++) {

System.out.println(club.getMembers().get(i).toString());

}

// find Member

Member r = club.findMember(member4);

System.out.println(r == null ? "Member Not Found" : ("Member Found " + r.toString()));

// Remove the element

club.removeMember(r);

// we removed the element so nothing will be returned after findMember

r = club.findMember(member4);

System.out.println(r == null ? ("Member Not Found") : ("Member Found " + r.toString()));

}

}

///////////////////////////End SportsManager.java/////////////////////////////////////////

////////////////////workspace 1 - Chegg Stuff/src/com/java/sportsClub/ClubManagerjava- Eclipse Eile Edit Source Refactor Navigate Search Projec Bun Window Help Quick Access ㄧ E. Problems @ Javadoc [쑤 Declaration Search- Progress -oo Call Hierarchy Console X □Properties <terminated» ClubManager [Java Application] C:\Program Files Java Name-Member1, membershipId-6, isFullyPaid-false Name-Member4, membership!d-45, îsFullyPaid-true Name-Member3, Name-Member2, membership!d-86, İsFullyPaid-true Member Found Name-Member4, membershipId-45, isFullyPaid-true Removed element Name-Member4, membership!d-45, İsFullyPaid-true Member Not Found 161 bin javaw.exe (22-Oct-2018, 9:58:56 P Ju membership!d-57, İsFullyPald-false O Type here to search s ENG 22:06 4* INTL 22-10-2018

Add a comment
Know the answer?
Add Answer to:
5: Assume that a Sports Club at the University wishes to store details about its members....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • its about in C++ You will implement a simple calendar application The implementation should include a class named Calendar, an abstract class named Event and two concrete classes named Task an...

    its about in C++ You will implement a simple calendar application The implementation should include a class named Calendar, an abstract class named Event and two concrete classes named Task and Appointment which inherit from the Event class The Event Class This will be an abstract class. It will have four private integer members called year, month, day and hour which designate the time of the event It should also have an integer member called id which should be a...

  • Design and implement a Java data structure class named BookShelf which has an array to store...

    Design and implement a Java data structure class named BookShelf which has an array to store books and the size data member. The class should have suitable constructors, get/set methods, and the toString method, as well as methods for people to add a book, remove a book, and search for a book. Design and implement a Java class named Book with two data members: title and price. Test the two classes by creating a bookshelf object and five book objects....

  • java A University would like to implement its students registery as a binary search tree, calledStudentBST....

    java A University would like to implement its students registery as a binary search tree, calledStudentBST. Write an Student node class, called StudentNode, to hold the following information about an Student: - id (as a int) - gpa (as double) StudentNode should have constructors and methods (getters, setters, and toString()) to manage Write the StudentBST class, which is a binary search tree to hold objects of the class StudentNode. The key in each node is the id. : import.java.ArrayList; public...

  • Java is an object-oriented programming language that enables us to define classes and to instantiate them...

    Java is an object-oriented programming language that enables us to define classes and to instantiate them into objects. These objects then call each other’s methods to implement the behavior of the application. The Unified Modeling Language (UML) is an object-oriented visual notation to document the design of object-oriented classes. For this discussion, you will practice designing a Java class called Course, drawing a UML class diagram for the Course class, and then implementing the Course class in Java code. Review...

  • Question 1) Consider a class Point that models a 2-D point with x and y coordinates. Define the c...

    C++ Question 1) Consider a class Point that models a 2-D point with x and y coordinates. Define the class point that should have the following Private data members x and y (of type int), with default values of 0 A constant ID of type int A private static integer data member named numOfPoints This data member should be o Incremented whenever a new point object is created. o Decremented whenever a point object is destructed. A default constructor An...

  • Create an Item class, which is the abstract super class of all Items.           Item class...

    Create an Item class, which is the abstract super class of all Items.           Item class includes an attribute, description of type String for every item. [for eg. Book]                                                             A constructor to initialize its data member of Item class.               Override toString() method to return details about the Item class. Create the ExtraCharge interface with the following details.                       Declare a constant RATE with value 0.25   Declare a method called calculateExtraCharge(), which returns a double value. Create the...

  • In this hormework, you will implement a simple caledar application The implernentation shauld inc...

    Do that with C++ and please add more comment that make it understandable In this hormework, you will implement a simple caledar application The implernentation shauld include a class narned Calendar, an abstract class named Event and two concrete classes narmed Task and Appointment which irherit from the Evernt class. The Event Class This will be an abstract class. It will have four private integer members called year, month, day and hour which desigate the tirne of the event. It...

  • I need to make a project named CStore. It is a Java starter project that only...

    I need to make a project named CStore. It is a Java starter project that only uses the console. I don't know how to even start it.. Please help me asap First I need to define 3 classes names Goods, Manage, UI. Then simply implement the Goods class, then make a function that inserts Goods object into a Goods list in the Manage class. In the UI class, the user inputs Goods that will be registered and that Goods will...

  • Design a class named NumDays, to store a value that represents a number of hours and...

    Design a class named NumDays, to store a value that represents a number of hours and convert it to a number of days. For example, 24 hours would be converted to 1 day, 36 hours would be converted to 1.5 days, and 54 hours would be converted to 2.25 days. This class has two private member variables with data type double: one is named as hours; another is named as days. This class has a constructor that accepts a value...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT