help needed with this topic

please help me with tis topic i could not find erors please help meeee

Page 1 of 1

5 Replies - 358 Views - Last Post: 20 April 2010 - 07:46 AM Rate Topic: -----

#1 scientist74372  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 24-March 10

help needed with this topic

Posted 18 April 2010 - 03:18 AM

((((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 occasionally. Each member has to pay a $ 10 yearly membership fee and receives 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.

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 :code:

This post has been edited by JackOfAllTrades: 18 April 2010 - 07:56 AM


Is This A Good Question/Topic? 0
  • +

Replies To: help needed with this topic

#2 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 988
  • View blog
  • Posts: 5,135
  • Joined: 28-September 06

Re: help needed with this topic

Posted 18 April 2010 - 03:31 AM

Please edit your posting (see the "EDIT" button in lower right).
( a ) Delete all your code.
( b ) Get a fresh copy of the code with formatting in place from your editor / IDE.
( c ) Paste the formatted code between code tags like this :code:
( d ) Use the "Preview Post" button to check it's all good.
( e ) Use the "Submit Modified Post" button to finish the editing.

Please give us some more details of your problem.
( a ) Does your code compile?
( b ) Any errors or warnings? If there are then share them with us.
( c ) Is the program producing any output?
( d ) How is the actual output different to what you want / expect? Give details and, ideally, examples.
Was This Post Helpful? 0
  • +
  • -

#3 sarmanu  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 965
  • View blog
  • Posts: 2,362
  • Joined: 04-December 09

Re: help needed with this topic

Posted 18 April 2010 - 03:34 AM

# include <iostream>
# include <string>
using namespace std;
void main ()

import java.util.Date;

public class Book


Epic! Java code along with C++ header files. main() floating too!! Oww...
Was This Post Helpful? 2
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5723
  • View blog
  • Posts: 22,637
  • Joined: 23-August 08

Re: help needed with this topic

Posted 18 April 2010 - 07:57 AM

Copy/paste programming FTW!!! Guessing the code came from here.
Was This Post Helpful? 0
  • +
  • -

#5 Guest_scientist74372*


Reputation:

Re: help needed with this topic

Posted 20 April 2010 - 07:41 AM

View PostJackOfAllTrades, on 18 April 2010 - 06:57 AM, said:

Copy/paste programming FTW!!! Guessing the code came from here.


yes u r write i was trying to solve it but i could not do it. thats why i have put that code so that i can know whats the error.........................
Was This Post Helpful? 0

#6 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5723
  • View blog
  • Posts: 22,637
  • Joined: 23-August 08

Re: help needed with this topic

Posted 20 April 2010 - 07:46 AM

The "error" is that's JAVA code, not C++. And we're not going to translate it for you.

The REAL error, however, is that you are a lazy copy/paste programmer who has no idea what you're doing.

Closed.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1