Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help with the below code!!!!! package shoppingCart; //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

Help with the below code!!!!!

package shoppingCart;

//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;

import java.text.SimpleDateFormat; //for the date

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 and 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();

}

}

Details of assignment

You will be provided a file named BookPrice.txt. This file contains the names and prices of various books, formatted as follows:

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

Each line in the file contains the name of a book, followed by a comma, followed by the books retail price. When your application begins execution, it should read the contents of the file and store the titles in a ListView. The user should be able to select a book from the list and add it to the Shopping Cart. The Shopping Cart is another ListView. The application should have buttons or menu items that allow the user to Add Selected Items, Remove Selected Items, and Check Out. When the Check Out button is selected, the application should calculate and display the subtotal of all books in the shopping cart, the sales tax of 7%, and the total. It should also create a receipt file, which should be a text file that includes the books purchased, the quantities of each book purchased, their prices, and total price both before and after taxes. Here is an example of what the receipt file could look like:

(File Name would be Receipt-12-15-2017.04.32.54.txt)
Receipt: 01-02-2018 02:47:15
Title Quantity Price Total
I Did It Your Way 1 $11.95 $11.95
The History of Scotland 2 $14.50 $29.00
Total $40.95
Tax $2.87
Grand Total $43.82

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Robb,Carlos Coronel

5th Edition

061906269X, 9780619062699

More Books

Students also viewed these Databases questions

Question

friendliness and sincerity;

Answered: 1 week ago