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.
Write a program that can process up to 1000 book titles and 500 members. Your program should contain a menu that gives the user different choices to effectively run the program))))
# include <iostream>
# include <string>
using namespace std;
void main ()
import java.util.Date;
public class Book
{
private int id;
private String title;
private String[] authors;
private String publisher;
private String ISBN;
private double price;
private Date publishingYear;
private int copyNumber;
private int authorsNumber;
public boolean checkTitle(String title)
{
if(null == title ||("".equals(title)))
{
return false;
}
if(title.equals(this.title))
{
return true;
}
return false;
}
public int getCopyNumber()
{
return copyNumber;
}
public void setCopyNumber(int copyNumber)
{
this.copyNumber = copyNumber;
}
public int getAuthorsNumber()
{
return authors.length;
}
public void setAuthorsNumber(int authorsNumber)
{
this.authorsNumber = authorsNumber;
}
public int getId()
{
return id;
}
public void setId(int id
) {
this.id = id;
}
public String getTitle()
{
return title;
}
public void setTitle(String title)
{
this.title = title;
}
public String[] getAuthors()
{
return authors;
}
public void setAuthors(String[] authors)
{
this.authors = authors;
}
public String getPublisher()
{
return publisher;
}
public void setPublisher(String publisher)
{
this.publisher = publisher;
}
public String getISBN() {
return ISBN;
}
public void setISBN(String isbn)
{
ISBN = isbn;
}
public double getPrice()
{
return price;
}
public void setPrice(double price)
{
this.price = price;
}
public Date getPublishingYear()
{
return publishingYear;
}
public void setPublishingYear(Date publishingYear)
{
this.publishingYear = publishingYear;
}
}
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class Member
{
private String name;
private int memberId;
private int boughtBookCount;
private double spentAmount;
private List<Book> boughtList = new ArrayList<Book>();
public List updataBookList(List<Book> newBoughtList)
{
List<Book> buyList = new ArrayList<Book>();
if(this.boughtList != null)
{
Iterator it = boughtList.iterator();
while(it.hasNext())
{
Book tempBook = (Book)it.next();
buyList.add(tempBook);
}
}
if(newBoughtList != null)
{
Iterator it = newBoughtList.iterator();
while(it.hasNext())
{
Book tempBook = (Book)it.next();
buyList.add(tempBook);
}
}
return buyList;
}
public List<Book> getBoughtList()
{
return boughtList;
}
public void setBoughtList(List<Book> boughtList)
{
this.boughtList = boughtList;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public int getMemberId()
{
return memberId;
}
public void setMemberId(int memberId)
{
this.memberId = memberId;
}
public int getBoughtBookCount()
{
return boughtBookCount;
}
public void setBoughtBookCount(int boughtBookCount)
{
this.boughtBookCount = boughtBookCount;
}
public double getSpentAmount()
{
return spentAmount;
}
public void setSpentAmount(double spentAmount)
{
this.spentAmount = spentAmount;
}
}
import java.util.List;
public interface BookStore
{
public void buy(Member m,List<Book> bookList);
public double getTotalMoney(List<Book> bookList);
}
import java.util.Iterator;
import java.util.List;
public class VIPCust implements BookStore
{
private double fee = 0.0;
public double getFee()
{
return fee;
}
public void setFee(double fee)
{
this.fee = fee;
}
public void buy(Member m, List<Book> bookList)
{
if(FeeHelper.getInstance().containsValue(m))
{
m.updataBookList(bookList);
m.setSpentAmount(m.getSpentAmount()+this.getTotalMoney(bookList));
this.fee = this.getTotalMoney(bookList)*5/100;
}
}
public double getTotalMoney(List<Book> bookList)
{
double totalMoney = 0.0;
Iterator<Book> iter = bookList.iterator();
while(iter.hasNext()){
Book b = (Book)iter.next();
totalMoney += b.getPrice();
}
return totalMoney;
}
}
import java.util.Iterator;
import java.util.List;
public class CommonCust implements BookStore
{
private double fee = 0.0;
public void buy(Member m,List<Book> bookList)
{
m.updataBookList(bookList);
m.setBoughtBookCount(m.getBoughtBookCount()+bookList.size());
m.setSpentAmount(m.getSpentAmount()+this.getTotalMoney(bookList));
if(m.getBoughtBookCount()>10)
{
this.fee = m.getSpentAmount()-this.getAvgMoney(m);
m.setBoughtBookCount(0);
m.setBoughtList(null);
}
}
public double getTotalMoney(List<Book> bookList)
{
double totalMoney = 0.0;
Iterator<Book> iter = bookList.iterator();
while(iter.hasNext()){
Book b = (Book)iter.next();
totalMoney += b.getPrice();
}
return totalMoney;
}
private double getAvgMoney(Member m)
{
double avgMoney =0.0;
Iterator<Book> it = m.getBoughtList().iterator();
for(int i=0;i<10;i++){
Book b = (Book)it.next();
avgMoney += b.getPrice();
}
return avgMoney/10;
}
public double getFee()
{
return fee;
}
public void setFee(double fee)
{
this.fee = fee;
}
}
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class FeeHelper implements Map
{
private Map feeMap = new HashMap();
public static FeeHelper instance = new FeeHelper();
public static FeeHelper getInstance()
{
if(null == instance)
{
return new FeeHelper();
}
return instance;
}
public void clear()
{
this.feeMap.clear();
}
public boolean containsKey(Object key)
{
if(this.feeMap.containsKey(key)){
return true;
}
return false;
}
public boolean containsValue(Object obj)
{
if(this.feeMap.containsKey(obj))
{
return true;
}
return false;
}
public Set entrySet()
{
return this.feeMap.entrySet();
}
public Object get(Object obj)
{
return this.feeMap.get(obj);
}
public boolean isEmpty()
{
return this.feeMap.isEmpty();
}
public Set keySet()
{
return this.feeMap.keySet();
}
public Object put(Object key, Object value)
{
return this.feeMap.put(key, value);
}
public void putAll(Map t)
{
this.feeMap.putAll(t);
}
public Object remove(Object key)
{
return this.feeMap.remove(key);
}
public int size()
{
return this.feeMap.size();
}
public Collection values()
{
return this.feeMap.values();
}
}
MOD EDIT: Added code tags. Please
This post has been edited by JackOfAllTrades: 18 April 2010 - 07:56 AM

New Topic/Question
This topic is locked




MultiQuote







|