diff options
| author | Kamal Wickramanayake <kamal@inbox.lk> | 2026-03-15 16:33:18 +0530 |
|---|---|---|
| committer | Kamal Wickramanayake <kamal@inbox.lk> | 2026-03-15 16:33:18 +0530 |
| commit | ee94d753a9f87d0b46b3aad3d3cf855056562ad2 (patch) | |
| tree | f5673b4b806e92b1d98f1167700d49535bea8338 /oop/10-point-of-sale/src/lk/ac | |
| parent | 7c40224d014257f9112da2ffceda3a357beb69a9 (diff) | |
Additional classes related to POS.
Diffstat (limited to 'oop/10-point-of-sale/src/lk/ac')
5 files changed, 92 insertions, 1 deletions
diff --git a/oop/10-point-of-sale/src/lk/ac/pdn/ceit/pos/App.java b/oop/10-point-of-sale/src/lk/ac/pdn/ceit/pos/App.java new file mode 100644 index 0000000..c3f1037 --- /dev/null +++ b/oop/10-point-of-sale/src/lk/ac/pdn/ceit/pos/App.java @@ -0,0 +1,16 @@ +package lk.ac.pdn.ceit.pos;
+
+import lk.ac.pdn.ceit.pos.item.InMemoryItemManager;
+import lk.ac.pdn.ceit.pos.item.ItemManager;
+
+public class App {
+ public static void main(String[] args) throws Exception {
+ ItemManager itemManager = new InMemoryItemManager();
+
+ PointOfSale pos = new PointOfSale(itemManager);
+
+ TextUI ui = new TextUI(pos);
+
+ ui.start();
+ }
+}
diff --git a/oop/10-point-of-sale/src/lk/ac/pdn/ceit/pos/PointOfSale.java b/oop/10-point-of-sale/src/lk/ac/pdn/ceit/pos/PointOfSale.java index 990a635..dfac6e1 100644 --- a/oop/10-point-of-sale/src/lk/ac/pdn/ceit/pos/PointOfSale.java +++ b/oop/10-point-of-sale/src/lk/ac/pdn/ceit/pos/PointOfSale.java @@ -11,6 +11,10 @@ public class PointOfSale { private Bill bill; + public PointOfSale(ItemManager itemManager) { + this.itemManager = itemManager; + } + public Bill createNewBill() { bill = new Bill(); return bill; diff --git a/oop/10-point-of-sale/src/lk/ac/pdn/ceit/pos/TextUI.java b/oop/10-point-of-sale/src/lk/ac/pdn/ceit/pos/TextUI.java new file mode 100644 index 0000000..056e41e --- /dev/null +++ b/oop/10-point-of-sale/src/lk/ac/pdn/ceit/pos/TextUI.java @@ -0,0 +1,27 @@ +package lk.ac.pdn.ceit.pos; + +import lk.ac.pdn.ceit.pos.entities.Bill; + +public class TextUI { + private PointOfSale pos; + + public TextUI(PointOfSale pos) { + this.pos = pos; + } + + public void start() { + IO.println("POS Started."); + + // Assume a bill should be created. + Bill bill = pos.createNewBill(); + + // Assume: Create a line item + pos.addLineItem("F001", 2); + + pos.addLineItem("F002", 3); + + // ... + + // Print bill + } +} diff --git a/oop/10-point-of-sale/src/lk/ac/pdn/ceit/pos/entities/Bill.java b/oop/10-point-of-sale/src/lk/ac/pdn/ceit/pos/entities/Bill.java index 0c2ff5f..ad6a87e 100644 --- a/oop/10-point-of-sale/src/lk/ac/pdn/ceit/pos/entities/Bill.java +++ b/oop/10-point-of-sale/src/lk/ac/pdn/ceit/pos/entities/Bill.java @@ -1,9 +1,10 @@ package lk.ac.pdn.ceit.pos.entities; +import java.util.ArrayList; import java.util.List; public class Bill { - private List<LineItem> lineItems; + private List<LineItem> lineItems = new ArrayList<>(); public List<LineItem> getLineItems() { return lineItems; diff --git a/oop/10-point-of-sale/src/lk/ac/pdn/ceit/pos/item/InMemoryItemManager.java b/oop/10-point-of-sale/src/lk/ac/pdn/ceit/pos/item/InMemoryItemManager.java new file mode 100644 index 0000000..00bc835 --- /dev/null +++ b/oop/10-point-of-sale/src/lk/ac/pdn/ceit/pos/item/InMemoryItemManager.java @@ -0,0 +1,43 @@ +package lk.ac.pdn.ceit.pos.item; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import lk.ac.pdn.ceit.pos.entities.Item; + +public class InMemoryItemManager implements ItemManager { + + // Assume this is the item storage + private Map<String, Item> items = new HashMap<>(); + + // Initial set of data for demo purposes + public InMemoryItemManager() { + this.create("Dhal", "F001", 300.00); + this.create("Bread", "F002", 180.00); + this.create("Sunlight Soap", "S001", 150.00); + } + + @Override + public Item findById(String id) { + return items.get(id); + } + + @Override + public List<Item> searchByName(String word) { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'searchByName'"); + } + + @Override + public Item create(String name, String id, double unitPrice) { + // Create a new Item + Item item = new Item(name, id, unitPrice); + + // Add to storage + items.put(id, item); + + return item; + } + +} |
