Question

In: Computer Science

A javafx gui that's meant to work like a shopping cart, which has 3 books how...

A javafx gui that's meant to work like a shopping cart, which has 3 books how did this happen 12.99, will benelli, 14.99, and where do I go, 10.99, you can remove from cart, clear cart, or checkout, and it should have a receipt of what you purchased. I am using eclipse, thanks.

Solutions

Expert Solution

Main.java

package sample;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.beans.value.ChangeListener;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.image.ImageView;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class Main extends Application {


    @Override
    public void start(Stage primaryStage) {
//        Button btn = new Button();
//        btn.setText("Say 'Hello World'");
//        btn.setOnAction(new EventHandler<ActionEvent>() {
//
//            @Override
//            public void handle(ActionEvent event) {
//                System.out.println("Hello World!");
//            }
//        });
        primaryStage.setTitle("Shopping cart App");


        FlowPane rootNode = new FlowPane();
        FlowPane list_items = new FlowPane();
        FlowPane list_items1 = new FlowPane();
        FlowPane check_pane = new FlowPane();







        rootNode.setVgap(10);
        list_items.setVgap(10);
        list_items.setHgap(85);
        list_items1.setVgap(10);
        list_items1.setHgap(10);
        check_pane.setHgap(10);


        rootNode.setPadding(new Insets(10, 10, 10, 10));


        Label items_pick = new Label("Items to pick:");
        Label your_cart = new Label("Your shopping cart:");
        Label result = new Label("");

        ListView<Product> listView = new ListView<>();
        Product Apple = new Product("Apple",5);
        Product Pumpkin = new Product("Pumpkin",15);
        Product Orange = new Product("Orange",10);
        Product Banana = new Product("Banana",12);
        Product Pear = new Product("Pear",25);

        listView.getItems().addAll(Apple,Pumpkin,Orange,Banana,Pear);
        listView.setPrefHeight(120);
        listView.setPrefWidth(100);


        Button add = new Button("Add");
        Button remove = new Button("Remove");
        Button checkout = new Button("Checkout");

        ListView<Product> cartView = new ListView<>();
        cartView.setPrefHeight(120);
        cartView.setPrefWidth(100); // sporno ako dobavish poveche ot 5

        add.setOnAction((ActionEvent event) -> {
            cartView.getItems().add(listView.getSelectionModel().getSelectedItem());
        });
        remove.setOnAction((ActionEvent event) -> {
            final int selectedIdx = cartView.getSelectionModel().getSelectedIndex();
            cartView.getItems().remove(selectedIdx);
        });
        checkout.setOnAction((ActionEvent event) -> {
            ObservableList<Product> res = cartView.getItems();
            double result_price = 0;
            for (Product tabPane : res){
                result_price += tabPane.getValue();
            }
            result.setText("Total price: " + result_price);
        });





        list_items.getChildren().addAll(items_pick,your_cart);
        list_items1.getChildren().addAll(listView,add,cartView,remove);
        check_pane.getChildren().addAll(checkout,result);



        //list_items.setAlignment(Pos.CENTER);


        rootNode.getChildren().addAll(list_items,list_items1,check_pane);



        Scene myScene = new Scene(rootNode,400,300



        primaryStage.setScene(myScene);
        primaryStage.show();

    }

    /**
      command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }

}

Product.java

package sample;

public class Product {
    String name;
    double price;
    Product(String name, double price){
        this.name = name;
        this.price = price;
    }
    public String toString(){
        return this.name + " - " + this.price;
    }
    double getValue(){
        return this.price;
    }
}

Hope This will help You .


Related Solutions

3. Are males or females more likely to return their shopping cart? Shoppers were observed at...
3. Are males or females more likely to return their shopping cart? Shoppers were observed at 7 different Walmarts at 9 different times. Of the 138 females that were observed, 121 returned their shopping cart. Of the 96 males that were observed, 76 returned their shopping cart. Is there evidence of a difference in the proportions of males and females who return their shopping cart at Walmart? a. Define the parameter(s) and state the hypotheses. b. What would be a...
Create a Python 3 program that acts as a grocery store shopping cart. 1. Create a...
Create a Python 3 program that acts as a grocery store shopping cart. 1. Create a class named GroceryItem. This class should contain: - an __init__ method that initializes the item’s name and price - a get_name method that returns the item’s name - a get_price method that returns the item’s price - a __str__ method that returns a string representation of that GroceryItem - an unimplemented method is_perishable Save this class in GroceryItem.py. 2. Create a subclass Perishable that...
How can the concept applied in the eCommerce shopping cart system be correlated to the phase...
How can the concept applied in the eCommerce shopping cart system be correlated to the phase of a system design in the software development life cycle(SDLC) process? Explain your answer.
In python 3 please: This program extends the earlier "Online shopping cart" program. (Start working from...
In python 3 please: This program extends the earlier "Online shopping cart" program. (Start working from your Program 7). (1) Build the ShoppingCart class with the following data attributes and related methods. Note: Some can be method stubs (empty methods) initially, to be completed in later steps.(3 pt) ● Parameterized constructor which takes the customer name and date as parameters ● Attributes ○ customer_name (string) ○ current_date (string) ○ cart_items (list) ● Methods ○ add_item() ■ Adds an item to...
Shopping Cart App (C#) Please create a C# Console (.NET Framework) application which reads from the...
Shopping Cart App (C#) Please create a C# Console (.NET Framework) application which reads from the user, the price of items in their shopping "cart". Be sure to tell the user how to stop (or ask them if they want to stop) entering prices. Items can be priced any positive number greater than zero. When the user has entered the prices for all items in their "cart", calculate the subtotal (the sum of all item prices). Next, check if the...
Shopping Bag: Assume the user has a bunch of purchases they would like to make. They...
Shopping Bag: Assume the user has a bunch of purchases they would like to make. They enter the price of each item, and the quantity and they want to add it to their cart. They tell us if they have more items to purchase, and if they do, we repeat getting the data and add the cost to the shopping bag. When they're done, we display the total. We will not account for Tax (yet) We will create a textual...
Can someone show me how to make this javaFx code work? The submit button should remain...
Can someone show me how to make this javaFx code work? The submit button should remain disabled until: ● There is text in all three fields. ● The two password fields have the same value. When Submit is clicked, display an Alert that says “Account Created!” When Quit is clicked, display an Alert that asks the user if they are sure they want to quit. If they click OK, quit the program with System.exit(0). If they click Cancel, the program...
Select the industry in which you work, worked or would like to work, or simply have...
Select the industry in which you work, worked or would like to work, or simply have an interest in. Which companies are the leaders in that particular industry? What practices have made them become a leader? What are the risks those companies face?
4) Two carts collide on a level track. Cart A has mass of 3 kg and...
4) Two carts collide on a level track. Cart A has mass of 3 kg and cart B has mass of 5 kg. Before the collision cart A moves towards stationary cart B with the speed of 5 m/s. a) What is the momentum of the system of two carts before the collision? b) What is the kinetic energy of the system of two carts before the collision? c) What is the momentum of the system of two carts after...
Whats the work culture like in Argentina? Typically day of work, how long, how many days...
Whats the work culture like in Argentina? Typically day of work, how long, how many days a week, what is the PTO like, work etiquettes?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT