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/////////////////////////////////////////
////////////////////
5: Assume that a Sports Club at the University wishes to store details about its members....
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 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. 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 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...
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 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...
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 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 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...