Java FX Shopping Cart system Create an application that works like a shopping ca
ID: 3690867 • Letter: J
Question
Java FX
Shopping Cart system
Create an application that works like a shopping cart system for an online book store. The text file named Bookprices.txt which you will create contains the names and prices of various books, format in the following fashion:
I did it your way 11.95
The History of Scotland 14.50
Learn Calculus in One Day 29.95
Feel the Stress 18.50
The Life of Mozart 18.95
The GUI interface also has two menu’s: a File menu and a Help menu. The File menu has an Exit menu item – when the user clicks the Exit menu item, the program ends. The Help menu has an About menu item that displays information related to the name of the application, a brief description of the application, its version number and an icon.
The close button ends the program and the title on the title bar has been set to something appropriate.
When your application begins execution, it should read the contents of the file and store the book titles in a ListView component. The user should be able to select a title(s) from the list and add it to the “shopping cart,” which is simply another ListView component. The application should have buttons or menu items that allow the user to remove items from the shopping cart, clear the shopping cart of all selections, and check out. When the user checks out, the application should calculate and display the subtotal of all the books in the shopping cart, the sales tax (which is 9% of the subtotal), and total.
Demonstrate your program by writing a driver class which should allows the user to browse, and select books (you will need a driver main and a class). Your program should include source, algorithm). Your program must start with a general comment which should include your name as programmer, description of the program, and any other pertinent info.
Explanation / Answer
public class ShoppingCart extends Stage implements Runnable { private ServerSocket serverSocket; private Socket clientSocket; private Socket socket; private final int port; private BufferedReader bReader; private BufferedWriter bWriter; private final ArrayList items = new ArrayList(); public ShoppingCart(int port) throws IOException { this.port = port; } /* * when an item arrives at the port, pass the port through to RecieveItem to digest the incomming stream */ @Override public void run() { boolean addMoreItems = true; try { this.serverSocket = new ServerSocket(port); } catch (IOException ex) { ex.printStackTrace(); } try { while(addMoreItems){ this.clientSocket = serverSocket.accept(); String theItem = receiveItem(clientSocket); if(theItem == null) addMoreItems = false; else this.items.add(theItem); } } catch (IOException ex) { ex.printStackTrace(); } } private String receiveItem(Socket socket) throws IOException { String readLine = ""; String itemString = ""; this.socket = socket; this.bReader = new BufferedReader(new InputStreamReader(socket.getInputStream())); while(readLine != null){ readLine = bReader.readLine(); // if we are finished adding items, proceed to checkout if(readLine.equalsIgnoreCase("checkout")) { // show cart for user to see items before paying itemString = null; } else { // otherwise, add the item itemString += "|" + readLine; } } return itemString; }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.