Question: Project 2 - Bookstore Membership Program Project Overview A small bookstore has implemented a membership loyalty program. Members pay $15 per year to belong. In
Project 2 - Bookstore Membership Program
Project Overview A small bookstore has implemented a membership loyalty program. Members pay $15 per year to belong. In return, members receive a 5% discount on all books purchased. In addition, when they have purchased 10 books, the (undiscounted) price of the last 10 books is averaged, and the average is applied as a discount toward the cost of the 11th book, up to the full price of the 11th book. If the discount is greater than the price of the 11th book, then the 11th book is free, but there is no cash refund. (If the average of the last 10 books bought is $20, and the 11th book costs $17, then the book is free but there is no refund of the other $3. If the 11th book costs $25, then the discounted price is $5.) After the discount is applied, the information about the previous 10 books is cleared and the process starts over. The discounted price of the 11th book is not counted as part of the next set of 10.
Input
You will write a program that will read in 2 data files. The first is a listing of bookstore members (ID number, first name, last name, number of books outstanding, and the prices of those books). The second is a listing of purchases (member ID, price of the purchased book).
Output
Your program will output (to the file named transactions.txt) each transaction, showing the members ID, members name, original undiscounted price, and the price charged after discounts.
Technical Requirements
Your program will implement the functionality by writing a BookstoreMember class. Your program must be object-oriented to receive credit. You will get zero if your program is not object-oriented.
Your BookstoreMember class should have the following private attributes:
An integer named memberID.
Two strings named firstName and lastName.
An array of floats named outstandingBooks.
An integer named numberOfPurchasedBooks.
Your BookstoreMember class should have the following public methods:
A default constructor that takes no parameters and sets the ID number to 0 and the first and last name to null. Also, it sets the numberOfPurchasedBooks to zero and initializes the array of outstandingBooks of size 10.
Getter for the members ID.
A method called fullName() that returns a String consisting of the last name, a comma and space, then the first name; a BookstoreMember with first name "Fred" and last name "Smith" would return "Smith, Fred" from this method.
A method called ReadData(). It takes a Scanner as its only parameter. It reads in an integer (ID number) and first and last name, in that order. It then reads an int N, where N ranges from 0 to 10, as the number of prices already stored, followed by N floats. All items are separated by whitespace. This method is not expected to return anything.
A method called DiscountedPrice() that takes a float as its parameter, and returns a float. If this is not the 11th book purchased by the member, then it stores the original (undiscounted) price and returns that value reduced by 5%. Otherwise, the 10 most recently purchased items are averaged, the average price applied as a discount subject to the rules above, stored values are cleared, and the discounted price returned. (Actually, it is unnecessary to clear the stored prices, only to reset the numberOfPurchasedBooks to zero. But that is an implementation detail.) You need to make sure that your return values should have no more than 2 decimal places. You can use Math.round() method to help you.
Your main() program should have the following actions in execution:
Create and initialize an array of BookstoreMembers. Your program may assume there are no more than 30 members in the file. You need a variable to store how many members are stored in the array.
If in the BookstoreMembers.txt file, there are more members to read in (while (scanner1.hasNext())), then use the ReadData() method to add one BookstoreMember into the end of the array.
If in the Purchases.txt file, there are more transactions to read in (while (scanner2.hasNext())), then read the members ID and original book price of the next transaction.
Based on the members ID, find the member in the array. Use a linear search to find a particular member.
Output the members ID, members full name, original book price and discounted book price (using the DiscountedPrice() method) separated by tab character ('\t').
You need to deal with the FileInputStreams, FileOutputStreams, Scanners and PrintWriters properly. Your program will be tested against different data files (with the same file names) of the same format. Neither members nor transactions are stored in any particular order.
Simple input
Purchases 26250 10.95
22152 46.44
26603 40.58
22152 64.56
12674 50.11
3002 39.04
26250 9.99
3002 41.30
2642 22.29
8278 25.42
5192 41.61
8278 9.88
8278 31.42
26603 12.00
26603 16.62
5192 44.81
26789 9.92
3002 30.06
26789 55.23
22152 60.40
26789 41.29
3002 43.58
22152 15.76
2642 70.59
26603 70.34
26250 57.38
2642 23.44
2642 29.23
8278 33.90
18521 29.53
3002 53.39
26789 51.21
26789 62.37
8278 32.40
26250 68.67
5192 36.95
26250 11.12
5192 45.27
26789 8.53
26250 24.71
8278 55.70
12674 53.73
22152 11.54
8278 48.06
26789 70.91
8278 30.50
26789 27.82
26789 42.41
26250 29.26
26789 46.02
3002 16.77
8278 50.05
22152 16.31
8278 35.90
8278 9.29
2642 39.41
26789 65.82
2642 9.57
12674 50.33
26603 56.64
26250 25.69
Bookstore
4002 Theodore Morris 6 11.15 34.34 25.37 18.39 54.89 59.52
13271 Alaina Chan 4 40.17 16.80 9.90 42.82
2144 Eric Morrison 7 38.99 14.61 37.61 14.28 34.06 27.42 20.52
6766 Kate Mann 7 41.27 54.96 51.36 7.11 35.45 64.81 67.57
2642 Saul Davidson 7 62.42 47.05 33.09 41.45 10.56 17.46 11.26
12674 Kaila Carter 3 23.29 45.47 52.31
9166 Moises Walsh 4 44.68 70.92 55.82 61.48
30434 Weston Luna 8 59.37 14.54 16.54 45.53 63.54 7.24 57.47 21.72
6547 Sadie Wood 4 37.72 19.68 60.78 28.18
24947 Noe Manning 1 48.61
18521 Ariel Rowe 7 16.72 31.57 9.92 49.34 40.76 60.69 56.24
5192 Kristin Paul 5 71.15 65.14 62.86 24.59 40.33
22152 Phoebe Terry 0
4142 Tommy Watkins 7 10.77 44.20 25.84 50.70 37.65 12.04 21.25
16516 Karina Jennings 4 39.84 61.75 25.09 66.45
26603 Tianna Jackson 9 16.71 67.55 25.19 13.34 53.54 17.80 61.34 36.55 16.59
20439 Cesar Bailey 1 14.69
26789 Maximilian Mann 0
32473 Alanna Singh 8 22.02 31.96 8.57 70.24 40.94 18.57 28.53 66.55
9988 Giovanni Hubbard 2 67.58 70.32
5277 Francis Wang 10 51.92 30.28 42.23 45.30 51.88 9.74 30.94 52.80 63.97 68.43
3539 Lance Perez 7 7.93 19.55 46.98 50.34 38.23 63.48 40.00
26250 Cade Guzman 8 16.88 31.07 34.95 28.17 23.89 43.27 70.00 39.31
3002 Salvador Hampton 5 67.47 41.48 71.10 71.07 70.60
8278 Raven Howard 8 46.46 16.71 19.98 44.75 49.25 64.20 16.71 16.39
6755 Ivan Rivera 7 55.20 25.91 32.36 33.66 21.13 22.24 22.91
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
