This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

abstract classes

 
mike karl
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this problem that this is my second semester in programming and i have assignments like this which i cannot understand since the teacher in Poland do not explain very well. i understand the usage of abstract classes, how they can be used and for what reasons, but what i dont understand in this example is how to (reference to the current user, or making a command like kate.buys(carrot))
i just need some help understanding this material

Problem 1.4 Write a set of classes representing shopping in a supermarket.

* Purchase: name of product, unit price, quantity.
* Cart: contains a list (collection) of products put into this cart, reference to the current user (object of class Customer) etc.
* Customer: name, reference to the currently used cart, list of bills (objects of class Bill) for purchases already completed and paid. Customer having a cart can put products into the cart (kate.buys(carrot)) and pay for all products at
checkout (object of class CheckOut) receiving the Bill.
*CheckOut: remembers customers who already have paid (kate.pays(checkout) and/or checkout.checksOut(kate) and their bills (which are also rememered by Customers). CheckOut can be asked for a report (object of class Report).
* Bill: represents bill with customers's name, date, list of products, amount paid etc.
* Report: report of checkout with list of bills paid at this checkout.
______________________________________________________________________________






 
Tony Docherty
Bartender
Posts: 2952
59
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what your question is or how it relates to the code you have posted. Please can you ask a specific question.

The code posted has some design issues for example:
Bread is not a kind of Purchase so should not extend a class called Purchase.
The Purchase class (which should be called something like Product or SalesItem) should implement the setQuantity() and getQuantity() methods as these will be the same for all sub classes.
Your Bread class has an instance variable called 'amount' this is a poor choice of name as it could mean the quantity or the cost.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And a setXXX() method should not usually have a return type.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic