Question: Use the bluej project called DateDotCom to complete the classes described in this handout. The Member class represents a specific member of a match making
Use the bluej project called DateDotCom to complete the classes described in this handout.
The Member class represents a specific member of a match making service. It stores the members id: id, the members age: age, the members gender: gender and the members hobbies: hobbies. Write the Member class according to the following specifications:
a. Add the four (4) fields that make up the Member class. (hobbies is an ArrayList of String)
b. Add a constructor that takes three (3) parameters: The first parameter is a String used to initialize the id of the member, the second parameter is an int used to initialize the age of the member and the third parameter is a String used to initialize the gender of the member. The field hobbies is initialized to an empty ArrayList of String.
c. Add a method called addHobby that takes one (1) parameter, a String hobby, which is the new hobby to be added to the field hobbies.
d. Add a method called memberEquals that takes one (1) parameter, a String id. If the id and the id of this are the same return true, otherwise return false. Note: the case of the letters in the Strings should not make a difference.
e. Add a method called memberToString. This method returns a String that is formatted exactly like example 1.
f. The method getHobbies is provided for you. This method returns the field hobbies as a String that can be used to display a members hobbies.
The MatchMaker class represents a match making companys client list. This class stores as many Member objects as the user wishes to enter. Create the MatchMaker class according to the following specifications:Write a static method called addHobbiesToMember that adds hobbies to a member. This method will be invoked by the main method. This method takes one (1) parameter, a Member object named member, which is used to add hobbies to.
In order to create this method declare the following local variables: 1) a String input, 2) a String output, 3) a String hobby, 4) a boolean finished.
Allow the user to enter new hobbies for the member until the user is finished.
Use a dialog box to ask the user for a new hobby for the member. Use the String output as the message for the showInputDialog method. output should be a concatenation of the members current hobby list and the MORE_HOBBIES message.
If the user enters either n or no (upper or lower case is ok), then they are finished entering hobbies and you need to exit the loop, otherwise add the hobby to the members hobby list and show the HOBBY_ADDED message.
Finish the main method following the steps below (like the main method used in previous labs and the previous homework). This method will allow a user to enter one or more Member objects into the system until the user says they are done entering members. Make sure to use the method testForCancel (defined in 2.d.) any time the user is asked for input. Do not use any variables in this method, except those already given to you.
1. Instantiate the members arraylist.
2. Add Member objects to members. Use the arrays ID, AGE and GENDER to get the corresponding parameters for the Member object. Make sure your code can adjust to the size of the arrays (all three arrays will always be equal in length). Each new member created in this loop also needs two hobbies. The hobbies are to be randomly picked from the HOBBIES array. (Do not worry if the same hobby is picked twice for the same member).
3. Create a loop that lasts until the user signals they are done adjusting the members list.
a. Use a dialog box to ask the user if they would like to show the members. If the user enters either y or yes (in any combination of lower or upper case letters) then show the user the members (use the showMembers method defined in 2.c.) and continue, otherwise just continue.
b. Use a dialog box to ask the user for the id of the member and then use a dialog box to ask the user for the age of the member and finally, use a dialog box to ask the user for the gender of the member. When getting the users input for the members gender, make sure you continue to ask until the user enters either an M or an F; upper or lower case is ok.
c. Reset correct to false for next use.
d. Create a Member object using the users input from the line above (2.b.3.b.)
e. Check to see if the id of the member object matches an id of a member in the members arraylist using the memberEquals method.
1. If the id from (2.b.3.b.) is a members id in members
Remember that the member was found.
Allow the user to enter a new hobbies for the member until the user is finished by calling the method addHobbiesToMember.
f. If the id entered from (2.b.3.b.) was not found in members, then this is a new member.
Allow the user to enter new hobbies for the new member until the user is finished by calling the method addHobbiesToMember.
Add the new member to members and show a message that the new member has been added.
g. Use a dialog box to ask the user if they would like to enter another member. If the user enters either y or yes (in any combination of lower or upper case letters) then then reset the found boolean variable and let the user continue entering members, otherwise indicate you are done and show the user the members (use the showMembers method defined below).
Write a static method called showMembers that will be invoked by the main method to print Member objects entered by the user. This method takes one parameter ArrayList<Member> named members. The output must be formatted exactly like example 2.
Write a static method called testForCancel that has one parameter a String test. If test is null then exit the program, otherwise do nothing.
Example 1:
ID : seriously38
Gender : F
Age : 38
Hobbies :
Tennis, Cooking.
Example 2:
Match Maker Database
---------------------------------
ID : seriously38
Gender : F
Age : 38
Hobbies :
Tennis, Cooking.
---------------------------------
ID : babyblueeyes
Gender : F
Age : 22
Hobbies :
Soccer, Reading.
---------------------------------
ID : holyroller
Gender : M
Age : 32
Hobbies :
Hunting, Fishing.
---------------------------------
ID : M3hImL33t
Gender : M
Age : 18
Hobbies :
Bowling, TV.
---------------------------------
ID : naturegrl
Gender : F
Age : 27
Hobbies :
Movies, Volleyball.
member class code
import java.util.ArrayList;
public class Member { private ArrayList
match maker class code
import java.util.ArrayList; import javax.swing.JOptionPane;
public class MatchMaker { private static final String TITLE = "Match Maker Database"; private static final String GET_ID = "Enter the client's id: "; private static final String GET_AGE = "Enter the client's age: "; private static final String GET_GENDER = "Enter the client's gender: (M for male, F for female)"; private static final String MORE_HOBBIES = " Enter more hobbies? (Enter the hobby or N or No to finish)"; private static final String MORE_MEMBERS = "Enter more members? (Y or Yes to enter more, N or No to exit and print report)"; private static final String SHOW_MEMBERS = "Show the member list? (Y or Yes to print the member list)"; private static final String HOBBY_ADDED = "The new hobby has been added."; private static final String MEMBER_ADDED = "The new member has been added."; private static final int QSTN = JOptionPane.QUESTION_MESSAGE; private static final int INFO = JOptionPane.INFORMATION_MESSAGE;
private static final String[] ID = {"seriously38", "babyblueeyes", "holyroller", "M3hImL33t", "naturegrl"}; private static final int[] AGE = { 38, 22, 32, 18, 27 }; private static final String[] GENDER = {"F", "F", "M", "M", "F"}; private static final String[] HOBBIES = {"Bowling", "Fishing", "Snow Boarding", "Skiing", "Soccer", "Hockey", "TV", "Reading", "Hunting", "Soccer", "Volleyball", "Tennis", "Cooking", "Eating", "Movies"};
public static void main(String[] args) { String input; //holds Strings returned from showInputDialog() String id; //client's id String gender; //client's gender int age; //client's age Member tempMember; //temporary member; int randomIndex; //used for the random index into an array boolean done = false; //used to determine if the user is done making entries boolean correct = false; //used to make sure an input is in the correct form boolean found = false; //used to determine if a new entry is already in the members ArrayList ArrayList
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
