Question: Create a Java GUI application that works like a shopping cart system for an online book store. PLEASE I really need help solving this! package
Create a Java GUI application that works like a shopping cart system for an online book store. PLEASE I really need help solving this!
package shoppingCart; /* Add your required multi-line comment here * */ //imports import javafx.application.Application; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.layout.VBox; import javafx.scene.layout.HBox; import javafx.geometry.Pos; import javafx.geometry.Insets; import javafx.scene.control.Label; import javafx.scene.control.Button; import javafx.scene.control.ListView; import javafx.scene.control.SelectionMode; import javafx.collections.ObservableList; import javafx.collections.FXCollections; import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; import java.util.Scanner; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintWriter; //for the date import java.text.SimpleDateFormat; public class ShoppingCart extends Application { /* ArrayList to hold info from the BookProces.txt file, cart information * and other required variables */ public static void main(String[] args) { // Launch the application. launch(args); } // start method entry point of the application @Override public void start(Stage primaryStage) { // Build the inventory ArrayLists // Convert the inventoryTtitles ArrayList to an ObservableList. // Build the Book ListView // Build the Shopping Cart ListView // Create the output label for the cart subtotal. // Create the output label for the tax. // Create the output label for the cart total. // Add To Cart Button Button addToCartButton = new Button("Add To Cart"); addToCartButton.setOnAction(e -> { // Get the selected index. // Add the item to the cart. if (index != -1) { // Update the cart ArrayLists // Update the cartListView // Update the subtotal } }); // Remove From Cart Button Button removeFromCartButton = new Button("Remove From Cart"); removeFromCartButton.setOnAction(e -> { // Get the selected index. // Add the item to the cart. if (index != -1) { // Update the subtotal // Remove the selected item from the cart ArrayLists // Update the cartListView } }); // Clear Cart Button Button clearCartButton = new Button("Clear Cart"); clearCartButton.setOnAction(e -> { // Update the subtotal // Clear the cart ArrayLists // Update the cartListView }); // Checkout Button Button checkoutButton = new Button("Checkout"); checkoutButton.setOnAction(e -> { final double TAX_RATE = 0.07; // Calculate the tax // Calculate the total //setup dates String timeStamp = new SimpleDateFormat("MM-DD-YYYY HH:mm:ss").format(Calendar.getInstance().getTime()); String fntimeStamp = new SimpleDateFormat("MM-DD-YYYY.HH.mm.ss").format(Calendar.getInstance().getTime()); //create and open receipt file String filename = "Receipt-"+fntimeStamp+".txt"; try { //open file PrintWriter receiptFile = new PrintWriter("src/shoppingCart/"+filename); //create the receipt //close the file receiptFile.close(); } catch (FileNotFoundException e1) { e1.printStackTrace(); System.out.println("file open error"); }
}); // Build the VBox to hold the Add button // Build the VBox to hold the cart buttons // Build the top part of the GUI // Build the bottom part of the GUI // Put everything into a VBox // Add the main VBox to a scene. // Set the scene to the stage aand display it. } private void readBookFile() throws IOException { String input; // To hold a line from the file // Open the file. File file = new File("src/shoppingCart/BookPrices.txt"); Scanner inFile = new Scanner(file); // Read the file. while (inFile.hasNext()) { // Read a line. // Tokenize the line.
// Add the book info to the ArrayLists. } // Close the file. inFile.close(); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
