permaculture playing cards
The moose likes Beginning Java and the fly likes abstract classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "abstract classes" Watch "abstract classes" New topic

abstract classes

mike karl

Joined: Mar 21, 2013
Posts: 13
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

Joined: Aug 07, 2007
Posts: 2839
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

Joined: Oct 13, 2005
Posts: 46412
And a setXXX() method should not usually have a return type.
I agree. Here's the link:
subject: abstract classes
It's not a secret anymore!