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.
_______________________________________________________________________________
1 2 3 4 5 6 7
|
public abstract class Purchase {
public abstract String getNameOfProduct();
public abstract int getUnitPrice();
public abstract int setQuantity(int a);
}
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
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;
}
}
|
1 2 3 4 5 6 7 8 9
|
import java.util.*;
public class Cart{
List<String> sCart = new ArrayList<String>();
public void addItem(String item){
sCart.add(item);
}
}
|
1 2 3 4 5 6 7 8 9 10 11
|
public abstract class Customer{
String name;
public void setName(String n){
name = n;
}
public String getName(){
return name;
}
}
|