DEAR JAVA EXPERTS.
can u help me? i dont know how to do the next move....
i want to write code that can make each object of the class Book can hold the following information about a book: title, up to four authors, publisher, ISBN, price, and number of copies in stock. To keep track of the number of author add another instance variable.
Include the methods to perform various operations on the objects of Book. For example, the usual operations that can be performed on the title are to show title, set the title, and check whether the title is the actual title of the book. Similarly, the typical operations that can be performed on the number of copies in stock are to show the number of copies in stock, set the number of copies in stock, update the number of copies in stock and return the number of copies in stock. Add similar operations for the publisher, ISBN, book price and authors. Add the appropriate constructors.
Design a class Member, in which each object of Member can hold the name of a person, member ID, number of books bought and amount spent. Include the methods to perform various operations of the class Member – for example, modify, set and show the person’s name. Similarly update, modify and show the number of books bought and amount spent. Add appropriate constructors.
Using the class Book and Member, 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 book store only occasionally. Each member has to pay RM10 as yearly membership fees and receives a 5% discount on each book bought.
For each member, the bookstore keeps track of the number of books bought 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 bought, applies this amount as a discount, and then reset the total amount spent to 0.
this is my code that i cant proceed...
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 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 +
"\nAuthor: " + author +
"\nPublisher: " + publisher +
"\nISBN: " + isbn +
"\nPrice: 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
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 +
"\nID: " + memberID +
"\nNo of books bought: " + noBooks +
"\nAmount Spent: " + amountSpent;
return str;
}
/**
The close method closes the file.
*/
public void close() throws IOException
{
inputFile.close();
}
}
please help mee...