Patrick help me
This commit is contained in:
parent
f2c2984db1
commit
012c9bcf61
14 changed files with 3445 additions and 84 deletions
|
@ -10,18 +10,16 @@ import javafx.scene.control.TableColumn;
|
|||
import javafx.scene.control.TableView;
|
||||
import javafx.scene.control.cell.PropertyValueFactory;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
public class CartController {
|
||||
|
||||
@FXML
|
||||
private Button cartBtn;
|
||||
private static final String CART_FILE = "cart.txt";
|
||||
|
||||
@FXML
|
||||
private Button loginBtn;
|
||||
|
||||
@FXML
|
||||
private Button btnCheckOut;
|
||||
private Button cartBtn, loginBtn, btnCheckOut;
|
||||
|
||||
@FXML
|
||||
private TableView<Item> cartContent;
|
||||
|
@ -39,15 +37,11 @@ public class CartController {
|
|||
private TableColumn<Item, Double> priceColumn;
|
||||
|
||||
@FXML
|
||||
private Label cartTitle;
|
||||
|
||||
@FXML
|
||||
private Label mainTitle;
|
||||
private Label cartTitle, mainTitle;
|
||||
|
||||
// Observable list to hold cart items
|
||||
private final ObservableList<Item> cartItems = FXCollections.observableArrayList();
|
||||
|
||||
// Initialize method to set up the TableView
|
||||
@FXML
|
||||
public void initialize() {
|
||||
// Set up columns to match Item properties
|
||||
|
@ -56,16 +50,27 @@ public class CartController {
|
|||
quantityColumn.setCellValueFactory(new PropertyValueFactory<>("quantity"));
|
||||
priceColumn.setCellValueFactory(new PropertyValueFactory<>("price"));
|
||||
|
||||
// Populate the cart table with sample data for demonstration
|
||||
cartItems.addAll(
|
||||
new Item("Book A", "A fascinating fantasy novel.", 1, 12.99),
|
||||
new Item("Book B", "A thrilling sequel.", 2, 10.50));
|
||||
// Load cart items from file
|
||||
loadCartItemsFromFile();
|
||||
|
||||
// Populate TableView with cart items
|
||||
cartContent.setItems(cartItems);
|
||||
}
|
||||
|
||||
private void loadCartItemsFromFile() {
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(CART_FILE))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
// Assuming each line contains only the book name for simplicity
|
||||
cartItems.add(new Item(line, "Book Description", 1, 9.99));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println("Error loading cart items: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void handleCartButton(ActionEvent event) {
|
||||
System.out.println("Cart button clicked!");
|
||||
try {
|
||||
App.setRoot("cart");
|
||||
} catch (IOException e) {
|
||||
|
@ -75,7 +80,6 @@ public class CartController {
|
|||
|
||||
@FXML
|
||||
private void handleLoginButton(ActionEvent event) {
|
||||
System.out.println("Login button clicked!");
|
||||
try {
|
||||
App.setRoot("login");
|
||||
} catch (IOException e) {
|
||||
|
@ -92,7 +96,7 @@ public class CartController {
|
|||
|
||||
System.out.println("Proceeding to checkout...");
|
||||
try {
|
||||
App.setRoot("checkout");
|
||||
App.setRoot("checkOut");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -110,7 +110,6 @@ public class CheckOutController {
|
|||
System.out.println("Form submitted successfully.");
|
||||
System.out.printf("Billing Info: %s, %s, %s, %s, %s\n", fullName, address, city, zip, country);
|
||||
System.out.printf("Credit Card Info: %s, %s, %s, CVV: %s\n", cardNumber, cardHolderName, expiryDate, cvv);
|
||||
// Process the payment here
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,23 +1,30 @@
|
|||
package com.example;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class Item {
|
||||
private String name;
|
||||
private String description;
|
||||
private int quantity;
|
||||
private double price;
|
||||
|
||||
// Constructor
|
||||
public Item(String name, String description, int quantity, double price) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.quantity = quantity;
|
||||
this.price = price;
|
||||
setName(name);
|
||||
setDescription(description);
|
||||
setQuantity(quantity);
|
||||
setPrice(price);
|
||||
}
|
||||
|
||||
// Getters and Setters
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
if (name == null || name.trim().isEmpty()) {
|
||||
throw new IllegalArgumentException("Item name cannot be null or empty");
|
||||
}
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
@ -26,6 +33,9 @@ public class Item {
|
|||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
if (description == null || description.trim().isEmpty()) {
|
||||
throw new IllegalArgumentException("Description cannot be null or empty");
|
||||
}
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
|
@ -34,6 +44,9 @@ public class Item {
|
|||
}
|
||||
|
||||
public void setQuantity(int quantity) {
|
||||
if (quantity < 0) {
|
||||
throw new IllegalArgumentException("Quantity cannot be negative");
|
||||
}
|
||||
this.quantity = quantity;
|
||||
}
|
||||
|
||||
|
@ -42,6 +55,33 @@ public class Item {
|
|||
}
|
||||
|
||||
public void setPrice(double price) {
|
||||
if (price < 0) {
|
||||
throw new IllegalArgumentException("Price cannot be negative");
|
||||
}
|
||||
this.price = price;
|
||||
}
|
||||
}
|
||||
|
||||
// Override equals and hashCode for object comparison
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
Item item = (Item) o;
|
||||
return Objects.equals(name, item.name) &&
|
||||
Objects.equals(description, item.description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name, description);
|
||||
}
|
||||
|
||||
// Override toString for better debugging and UI representation
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("Item{name='%s', description='%s', quantity=%d, price=%.2f}",
|
||||
name, description, quantity, price);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package com.example;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
|
@ -9,6 +10,8 @@ import javafx.scene.control.TextArea;
|
|||
|
||||
public class ShopController {
|
||||
|
||||
private static final String CART_FILE = "cart.txt";
|
||||
|
||||
@FXML
|
||||
private Button cartBtn;
|
||||
|
||||
|
@ -16,59 +19,20 @@ public class ShopController {
|
|||
private Button loginBtn;
|
||||
|
||||
@FXML
|
||||
private Button cardBtn1;
|
||||
|
||||
private Button cardBtn1, cardBtn2, cardBtn3, cardBtn4;
|
||||
@FXML
|
||||
private Button cardBtn2;
|
||||
|
||||
@FXML
|
||||
private Button cardBtn3;
|
||||
|
||||
@FXML
|
||||
private Button cardBtn4;
|
||||
|
||||
@FXML
|
||||
private Button cardBtn5;
|
||||
|
||||
@FXML
|
||||
private Button cardBtn6;
|
||||
|
||||
@FXML
|
||||
private Button cardBtn7;
|
||||
|
||||
@FXML
|
||||
private Button cardBtn8;
|
||||
private Button cardBtn5, cardBtn6, cardBtn7, cardBtn8;
|
||||
|
||||
@FXML
|
||||
private Label mainTitle;
|
||||
|
||||
@FXML
|
||||
private TextArea cardText1;
|
||||
|
||||
private TextArea cardText1, cardText2, cardText3, cardText4;
|
||||
@FXML
|
||||
private TextArea cardText2;
|
||||
|
||||
@FXML
|
||||
private TextArea cardText3;
|
||||
|
||||
@FXML
|
||||
private TextArea cardText4;
|
||||
|
||||
@FXML
|
||||
private TextArea cardText5;
|
||||
|
||||
@FXML
|
||||
private TextArea cardText6;
|
||||
|
||||
@FXML
|
||||
private TextArea cardText7;
|
||||
|
||||
@FXML
|
||||
private TextArea cardText8;
|
||||
private TextArea cardText5, cardText6, cardText7, cardText8;
|
||||
|
||||
@FXML
|
||||
public void initialize() {
|
||||
// Initialization logic can go here.
|
||||
System.out.println("ShopController initialized.");
|
||||
}
|
||||
|
||||
|
@ -82,51 +46,59 @@ public class ShopController {
|
|||
App.setRoot("login");
|
||||
}
|
||||
|
||||
// Book Addition Handlers
|
||||
@FXML
|
||||
private void handleAddToCartButton1() {
|
||||
System.out.println("Added 'Lord of the Rings' to cart!");
|
||||
// Logic for adding the first book to the cart.
|
||||
addToCart("Lord of the Rings");
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void handleAddToCartButton2() {
|
||||
System.out.println("Added 'The Wheel of Time' to cart!");
|
||||
// Logic for adding the second book to the cart.
|
||||
addToCart("The Wheel of Time");
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void handleAddToCartButton3() {
|
||||
System.out.println("Added 'The Chronicles of Narnia' to cart!");
|
||||
// Logic for adding the third book to the cart.
|
||||
addToCart("The Chronicles of Narnia");
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void handleAddToCartButton4() {
|
||||
System.out.println("Added 'The Earthsea Cycle' to cart!");
|
||||
// Logic for adding the fourth book to the cart.
|
||||
addToCart("The Earthsea Cycle");
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void handleAddToCartButton5() {
|
||||
System.out.println("Added 'The First Law Trilogy' to cart!");
|
||||
// Logic for adding the fifth book to the cart.
|
||||
addToCart("The First Law Trilogy");
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void handleAddToCartButton6() {
|
||||
System.out.println("Added 'The Kingkiller Chronicle' to cart!");
|
||||
// Logic for adding the sixth book to the cart.
|
||||
addToCart("The Kingkiller Chronicle");
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void handleAddToCartButton7() {
|
||||
System.out.println("Added 'The Mistborn Series' to cart!");
|
||||
// Logic for adding the seventh book to the cart.
|
||||
addToCart("The Mistborn Series");
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void handleAddToCartButton8() {
|
||||
System.out.println("Added 'The Stormlight Archive' to cart!");
|
||||
// Logic for adding the eighth book to the cart.
|
||||
addToCart("The Stormlight Archive");
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the specified item to the cart by appending it to the cart file.
|
||||
*
|
||||
* @param bookTitle the title of the book to add to the cart
|
||||
*/
|
||||
private void addToCart(String bookTitle) {
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(CART_FILE, true))) {
|
||||
writer.write(bookTitle);
|
||||
writer.newLine();
|
||||
System.out.println("Added to cart: " + bookTitle);
|
||||
} catch (IOException e) {
|
||||
System.err.println("Failed to add item to cart: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1700
Code/ost/JAVA-FX-PROJECT/hs_err_pid18058.log
Normal file
1700
Code/ost/JAVA-FX-PROJECT/hs_err_pid18058.log
Normal file
File diff suppressed because it is too large
Load diff
1646
Code/ost/JAVA-FX-PROJECT/hs_err_pid18228.log
Normal file
1646
Code/ost/JAVA-FX-PROJECT/hs_err_pid18228.log
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue