Assignment 5
due Thursday, February 14 at 11:59pm on Canvas
Pair Programming Extra Credit Opportunity (1 pt)
- Both partners fill in, sign, date, and submit the pair programming contract
- Upload the document(s) along with your source code files to Canvas.
- Only ONE partner submits the assignment to Canvas. Please make sure both your names are on the files.
Valued Rewards Members (10 pts)
- In this assignment, we will be bring inheritance and static methods and variables to your User and Profile Assignment
- In the same project folder as your previous assignment, create a new class named RewardMember.java
- Here is the important information about this class:
- RewardMember is a subclass of User
- It has two private static variables:
- numRewardMembers, an integer, which is initialized to 0
- rewardNumber, an integer, which is initialized to 99556
- It has one private (non static) variable:
- It has two constructors:
- A default constructor, which calls the constructor of the super class, and also initializes memberNumber to be "number unknown"
- A 6-argument constructor, which calls the 5-argument constructor of the super class, and also initializes memberNumber to be a value passed in as a parameter
- It has one mutator method to update the value of member number.
- The name of the mutator is setMemberNumber.
- It takes in one String parameter
- It returns nothing
- It has one accessor method to return the value of member number:
- The name of the accessor is getMemberNumber
- It has no parameters
- It returns a String
- It has one static accessor method to return the value of numRewardsMembers
- The name of the method is getNumRewardsMembers
- It has no parameters
- It returns an int
- It has one static mutator method to increment the value of numRewardsMembers
- The name of the method is updateNumRewardsMembers
- It has no parameters
- It returns nothing.
- It has one additional static method as follows:
- The name of the method is generateRewardNumber
- It increments rewardNumber by 1
- It returns rewardNumber as a String
- It Overrides toString by calling the superclass toString and also concatenating the member number
- Open up the User.java class and be ready to make some additional alterations, as follows:
- Declare a private static variable at the top of the class named numUsers and initialize it to 0.
- Add a static accessor method called getNumUsers:
- This method is static
- It returns an int for the number of users
- It takes no parameters
- Add a static mutator method called updateNumUsers
- This method is static
- It takes in no parameters and returns nothing
- It updates the numUsers variable by 1
- Now, we will also alter the names.txt input file. Copy and paste the below contents into names.txt file:
Jiming Wu F 4082123458 jwu@gmail.com abc123 RM 987684 James Brown M 8315678432 jaime.boy.brown@hotmail.com jjjbbb123 NRM 0 Leanna Perez F 4087654433 leaperez@yahoo.com letmein NRM 0 Xing Li M 8313214555 xing.li@sbcglobal.net 555!!!hi NRM 0 Stacey Cahill O 8312123333 scahill@gmail.com r0tr@tr^n RM 945544 Mohammed Abbas M 4083134444 downtown_abbas@yahoo.com 1@m@bb@s RM 945575 Kumari Chakrabarti F 4086667777 kukuchakrabarti@hotmail.com passw0rd NRM 0 Shakil Smith M 4082123333 shakattaq@gmail.com qwerty RM 945682 Jung Ahrin F 8319257788 jung_ahrin@yahoo.com password1 NRM 0 Pedro Martinez M 4086162323 pedro2018@sbcglobal.net 123456789 RM 945873 Ally Gu O 4089256776 i_am_ally@comcast.net trustno1 NRM 0 Tamara White F 8317778978 tamtastic@gmail.com 1qaz2wsx RM 956689 Alvin Ngo M 4089256677 drngo@hotmail.com qwertyuiop NRM 0 Abir Fadel M 8316645325 greatabs@comcast.com qazwsx RM 942211 Brad Feinman M 8312023443 bradisrad@gmail.com 11111 NRM 0 Xiaohang Yue M 8318990033 yue95@yahoo.com adobe123 NRM 0 - Note that this file now contains information about whether each user is also a rewards member.
- For those users who are rewards members, the acronym RM appears in the line below their passwords, along with a member number on the next line.
- For those users who are not rewards members, the acronym NRM appears in the line below their passwords, along with a 0 on the next line to indicate no member number
- In Profiles.java, declare a new ArrayList to store RewardMember objects.
- As you read in the contents of the names.txt file, any User who is also a RewardMember should be inserted into both ArrayLists.
- The program should then adapt to 4 different types of users:
- Users who are rewards members
- Users who are not rewards members
- New users who do not appear in names.txt (must create an account) AND decide to become rewards members
- New users who do not appear in names.txt (must create an account) and decide NOT to become rewards members
- To search for rewards members, in the new ArrayList, alter the signature of linearSearch as follows:
public int linearSearch(String email, String password, ArrayList<RewardMember> rm) - Leave bubbleSort and binarySearch unchanged.
- Now, linearSearch will be used exclusively to search for rewards members in the new ArrayList
- bubbleSort and binarySearch will be used exclusively to search for users in the users ArrayList
- Make any additional changes you need to produce output like that shown below.
- When you are finished, upload User.java, RewardMember.java and Profile.java to Canvas
- Note that your program should still write the users ArrayList to accounts.txt before the program ends.
Sample Output - Example Showing User Who is Not a Reward Member:
Welcome!
We are proudly serving 16 users and counting!
Enter your email address: kukuchakrabarti@hotmail.com Enter your password: passw0rd
Hi, Kumari Chakrabarti! We have the following information on file for you: Name: Kumari Chakrabarti Gender: F Phone: (408)666-7777 Email: kukuchakrabarti@hotmail.com
Sample Output - Example Showing User Who is a Reward Member:
Welcome!
We are proudly serving 16 users and counting!
Enter your email address: pedro2018@sbcglobal.net Enter your password: 123456789
Welcome valued reward member, Pedro Martinez!
We have the following information on file for you: Name: Pedro Martinez Gender: M Phone: (408)616-2323 Email: pedro2018@sbcglobal.net Member Number: 945873
Thank you for being one of our 7 valued reward members. To show our appreciation, enjoy 10% off all shopping today!
Have a great day!
Sample Output - Example Showing a New User Who Becomes a Reward Member:
Welcome!
We are proudly serving 16 users and counting!
Enter your email address: myEmail@gmail.com Enter your password: iforgetit
Sorry! We don't have your account on file. Let's create an account for you!
Enter your name: Joe Schmoe Enter your gender: M Enter your 10 digit phone number (no spaces or punctuation): 1112223344
Thank you, Joe Schmoe! Your account has now been created.
Name: Joe Schmoe Gender: M Phone: (111)222-3344 Email: myEmail@gmail.com
Would you like to join our Reward Member program and save 10% off all purchases today? Enter yes or no: Yes
Thank you! In exchange for becoming a valued member, we reserve the right to collect detailed information about you and your shopping habits and sell this information to other companies.
Here is your new member number: 99557
Have a great day!
Sample Output - Example Showing a New User Who Does Not Become a Reward Member:
Welcome!
We are proudly serving 16 users and counting!
Enter your email address: myEmail@gmail.com Enter your password: iforgetit
Sorry! We don't have your account on file. Let's create an account for you!
Enter your name: Joe Schmoe Enter your gender: M Enter your 10 digit phone number (no spaces or punctuation): 1112223344
Thank you, Joe Schmoe! Your account has now been created.
Name: Joe Schmoe Gender: M Phone: (111)222-3344 Email: myEmail@gmail.com
Would you like to join our Reward Member program and save 10% off all purchases today? Enter yes or no: no
Goodbye!
|
|