Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using the classes designed in PE 6 and 7, write a program to simulate a bookstor

ID: 3627877 • Letter: U

Question

Using the classes designed in PE 6 and 7, write a program to simulate a bookstore. The bookstore has two types of customers: those who are members of the bookstore and those who buy books from the bookstore only ocasionally. Each member has to pay a 10$ yearly membership fee and recieves a 5% discount on each book purchased.

For each member, the bookstore keeps track of the number of books purchased and the total amount spent. For every eleventh book that a member buys, the bookstore takes the average of the total amount of the last 10 books purchased, applies this amount as a discount, and then resets the total amount spent to 0.

Explanation / Answer

/** The TestScoreReader class reads test scores as tokens from a file and calculates the average of each line of scores. */ public class Book { private FileReader freader; private BufferedReader inputFile; private String line; /** The constructor opens a file to read the grades from. @param filename The file to open. */ public Book(String filename) throws IOException { freader = new FileReader(filename); inputFile = new BufferedReader(freader); } /** The readNextLine method reads the next line from the file. @return true if the line was read, false otherwise. */ public boolean readNextLine() throws IOException { boolean lineRead; // Flag variable // Get the next line. line = inputFile.readLine(); // Determine whether the line was read. if (line != null) lineRead = true; else lineRead = false; return lineRead; } public String tokenTime() throws IOException { String name; String author; String publisher; String isbn; String price; String str; StringTokenizer token = new StringTokenizer(line, ","); name = token.nextToken(); author = token.nextToken(); publisher = token.nextToken(); isbn = token.nextToken(); price = token.nextToken(); str = "Name: " + name + " Author: " + author + " Publisher: " + publisher + " ISBN: " + isbn + " Price: RM" + price; return str; } /** The close method closes the file. */ public void close() throws IOException { inputFile.close(); } } the body... import java.io.*; // Needed for IOException import javax.swing.JOptionPane; /** This program uses the TestScoreReader class to read test scores from a file and get their averages. */ public class Demo { public static void main(String[] args) throws IOException { // Create a TestScoreReader object. Book scoreReader = new Book("as.txt"); Member member = new Member("mem.txt"); // Display the averages. while (scoreReader.readNextLine()) { JOptionPane.showMessageDialog(null, scoreReader.tokenTime() , "BOOK", JOptionPane.INFORMATION_MESSAGE); while (member.readNextLine()) { //JOptionPane.showMessageDialog(null, member.tokenTime() , "MEMBER", JOptionPane.INFORMATION_MESSAGE); } } // Close the TestScoreReader. scoreReader.close(); } } the books is refer to here... Starting Out with Java, Gaddis and Muganda, Pearson, 890-345-566, 76.90 Modul Hubungan Etnik, Shamsul Amri Baharudin, Pusat Penerbitan Universiti(UPENA), 234-234-344, 20.00 and this is for the member (Toggle Plain Text) import java.io.*; import java.util.StringTokenizer; /** The TestScoreReader class reads test scores as tokens from a file and calculates the average of each line of scores. */ public class Member { private FileReader freader; private BufferedReader inputFile; private String line; /** The constructor opens a file to read the grades from. @param filename The file to open. */ public Member(String filename) throws IOException { freader = new FileReader(filename); inputFile = new BufferedReader(freader); } /** The readNextLine method reads the next line from the file. @return true if the line was read, false otherwise. */ public boolean readNextLine() throws IOException { boolean lineRead; // Flag variable // Get the next line. line = inputFile.readLine(); // Determine whether the line was read. if (line != null) lineRead = true; else lineRead = false; return lineRead; } public String tokenTime() throws IOException { String str; String name; String memberID; String noBooks; String amountSpent; StringTokenizer token = new StringTokenizer(line, ","); name = token.nextToken(); memberID = token.nextToken(); noBooks = token.nextToken(); amountSpent = token.nextToken(); str = "Name: " + name + " ID: " + memberID + " No of books bought: " + noBooks + " Amount Spent: " + amountSpent; return str; } /** The close method closes the file. */ public void close() throws IOException { inputFile.close(); } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote