package lk.ac.pdn.ceit.pos.ui; import java.util.List; import lk.ac.pdn.ceit.pos.PointOfSale; import lk.ac.pdn.ceit.pos.entities.Bill; import lk.ac.pdn.ceit.pos.entities.Item; import lk.ac.pdn.ceit.pos.entities.LineItem; public class TextUI { private PointOfSale pos; private Bill bill; // Current bill private void printBill() { // Print top part of the bill IO.println(bill); // TODO: Only print suitable parts for the top of the bill. // Print line items for (LineItem lineItem : bill.getLineItems()) { IO.println(lineItem); } // TODO: Print total, cash given, balance, etc. } public void setPos(PointOfSale pos) { this.pos = pos; } public void start() { IO.println("POS Starting..."); printHelp(); while (true) { String response = IO.readln("POS> "); switch (response.trim().toLowerCase()) { case "q": case "quit": IO.println("Bye bye!"); System.exit(0); case "help": printHelp(); break; case "create": bill = pos.createNewBill(); IO.println("New bill created. Bill id: " + bill.getId()); break; case "search": String q = IO.readln("Enter search query (item name): "); List items = pos.searchItems(q); IO.println("Search results: "); for (Item item : items) { IO.println(item); } break; case "item": String itemId = IO.readln("Enter item Id: "); String quantity = IO.readln("Enter quantity: "); pos.addLineItem(itemId, Integer.parseInt(quantity)); break; case "save": pos.saveBill(); IO.println("Bill saved."); break; case "finish": pos.finishBillSession(); this.bill = null; IO.println("Bill session finished."); break; case "print": printBill(); break; default: IO.println("Command not understood."); break; } } } private void printHelp() { IO.println("Commands available:"); IO.println(" q or quit - Quit the program."); IO.println(" help - Prints this help."); IO.println(" create - Create a new bill."); IO.println(" item - Enter new item details to be purchased."); IO.println(" save - Save the current bill in the system."); IO.println(" print - Print the bill."); IO.println(" finish - Finish current bill session."); } }