Question
Create a Java GUI application that works like a shopping cart system for an online book store. 1 package shoppingCart; 2 3 /* Add your
Create a Java GUI application that works like a shopping cart system for an online book store.
1 package shoppingCart; 2 3 /* Add your required multi-line comment here 4 * 5 */ 6 7 //imports 8 import javafx.application.Application; 9 import javafx.stage.Stage; 10 import javafx.scene.Scene; 11 import javafx.scene.layout.VBox; 12 import javafx.scene.layout.HBox; 13 import javafx.geometry.Pos; 14 import javafx.geometry.Insets; 15 import javafx.scene.control.Label; 16 import javafx.scene.control.Button; 17 import javafx.scene.control.ListView; 18 import javafx.scene.control.SelectionMode; 19 import javafx.collections.ObservableList; 20 import javafx.collections.FXCollections; 21 import java.util.ArrayList; 22 import java.util.Calendar; 23 import java.util.Collections; 24 import java.util.Scanner; 25 import java.io.File; 26 import java.io.FileNotFoundException; 27 import java.io.IOException; 28 import java.io.PrintWriter; 29 //for the date 30 import java.text.SimpleDateFormat; 31 32 33 34 public class ShoppingCart extends Application 35 { 36 /* ArrayList to hold info from the BookProces.txt file, cart information 37 * and other required variables 38 */ 39 40 41 42 43 public static void main(String[] args) 44 { 45 // Launch the application. 46 launch(args); 47 } 48 49 50 // start method entry point of the application 51 @Override 52 public void start(Stage primaryStage) 53 { 54 // Build the inventory ArrayLists 55 56 // Convert the inventoryTtitles ArrayList to an ObservableList. 57 58 // Build the Book ListView 59 60 // Build the Shopping Cart ListView 61 62 // Create the output label for the cart subtotal. 63 64 // Create the output label for the tax. 65 66 // Create the output label for the cart total. 67 68 // Add To Cart Button 69 Button addToCartButton = new Button("Add To Cart"); 70 addToCartButton.setOnAction(e -> 71 { 72 // Get the selected index. 73 74 // Add the item to the cart. 75 if (index != -1) 76 { 77 // Update the cart ArrayLists 78 79 // Update the cartListView 80 81 // Update the subtotal 82 } 83 }); 84 85 // Remove From Cart Button 86 Button removeFromCartButton = new Button("Remove From Cart"); 87 removeFromCartButton.setOnAction(e -> 88 { 89 // Get the selected index. 90 91 // Add the item to the cart. 92 if (index != -1) 93 { 94 // Update the subtotal 95 96 // Remove the selected item from the cart ArrayLists 97 98 // Update the cartListView 99 } 100 }); 101 102 // Clear Cart Button 103 Button clearCartButton = new Button("Clear Cart"); 104 clearCartButton.setOnAction(e -> 105 { 106 // Update the subtotal 107 108 // Clear the cart ArrayLists 109 110 // Update the cartListView 111 }); 112 113 // Checkout Button 114 Button checkoutButton = new Button("Checkout"); 115 checkoutButton.setOnAction(e -> 116 { 117 final double TAX_RATE = 0.07; 118 119 // Calculate the tax 120 121 // Calculate the total 122 123 //setup dates 124 String timeStamp = new SimpleDateFormat("MM-DD-YYYY HH:mm:ss").format(Calendar.getInstance().getTime()); 125 String fntimeStamp = new SimpleDateFormat("MM-DD-YYYY.HH.mm.ss").format(Calendar.getInstance().getTime()); 126 127 //create and open receipt file 128 String filename = "Receipt-"+fntimeStamp+".txt"; 129 try { 130 //open file 131 PrintWriter receiptFile = new PrintWriter("src/shoppingCart/"+filename); 132 133 //create the receipt 134 135 //close the file 136 receiptFile.close(); 137 } catch (FileNotFoundException e1) { 138 e1.printStackTrace(); 139 System.out.println("file open error"); 140 } 141 142 }); 143 144 // Build the VBox to hold the Add button 145 146 // Build the VBox to hold the cart buttons 147 148 // Build the top part of the GUI 149 150 // Build the bottom part of the GUI 151 152 // Put everything into a VBox 153 154 // Add the main VBox to a scene. 155 156 // Set the scene to the stage aand display it. 157 } 158 159 private void readBookFile() throws IOException 160 { 161 String input; // To hold a line from the file 162 163 // Open the file. 164 File file = new File("src/shoppingCart/BookPrices.txt"); 165 Scanner inFile = new Scanner(file); 166 167 // Read the file. 168 while (inFile.hasNext()) 169 { 170 // Read a line. 171 172 // Tokenize the line. 173 174 // Add the book info to the ArrayLists. 175 } 176 177 // Close the file. 178 inFile.close(); 179 } 180 }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started