### Abstract classes

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.
_______________________________________________________________________________

 ``1234567`` ``````public abstract class Purchase { public abstract String getNameOfProduct(); public abstract int getUnitPrice(); public abstract int setQuantity(int a); }``````

 ``1234567891011121314151617181920212223`` `````` public class Bread extends Purchase{ int amount = 0; @Override public String getNameOfProduct() { return "Bread"; } @Override public int getUnitPrice() { return 3 * amount; } @Override public int setQuantity(int a) { return amount += a; } public int getQuantity(){ return amount; } }``````

 ``123456789`` ``````import java.util.*; public class Cart{ List sCart = new ArrayList(); public void addItem(String item){ sCart.add(item); } }``````

 ``1234567891011`` ``````public abstract class Customer{ String name; public void setName(String n){ name = n; } public String getName(){ return name; } }``````
This is C++ forum, not a java one.
In C++ if some class is abstract you cannot use object of this class.
You should develop also inherited non-abstract class and then you can create objects of this new non-abstract class. I suppose that everything is similar in java.
my bad, how do i remove post
Topic archived. No new replies allowed.