-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomerCostScreen.java
More file actions
74 lines (60 loc) · 2.06 KB
/
CustomerCostScreen.java
File metadata and controls
74 lines (60 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package bookstoreapp;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.scene.text.*;
import javafx.scene.layout.*;
import javafx.stage.Stage;
import javafx.geometry.*;
import java.math.*;
/**
*
* @author Carlos Bolinas
*/
public class CustomerCostScreen {
public Group display(Stage primaryStage, Customer c, double cost, boolean redeem){
// Point calculation
int reduction;
if(redeem == true){
// If customer doesn't have enoough points
if (cost >= c.getPts()/100){
reduction = c.getPts()/100;
}
// If customer has more than enough points
else{
reduction = (int)cost;
}
cost -= reduction;
c.setPts(c.getPts() - reduction*100);
}
// 1 CAD spent = 10 pts added
c.setPts(c.getPts() + ((int)cost*10));
// Update status
if (c.getPts() < 1000){
c.setStatus("Silver");
}else{
c.setStatus("Gold");
}
Group screen = new Group();
// Total Cost display
Text totalCost = new Text("Total cost: $" + cost);
totalCost.setFont(new Font(14));
// Points and Status display
Text mid = new Text("Points: " + c.getPts() + ", Status: " + c.getStatus());
mid.setFont(new Font(14));
// Logout button
Button logout = new Button("Logout");
logout.setOnAction(e ->{
// Switch to login screen
BookstoreApp app = (BookstoreApp) primaryStage.getUserData();
if (app != null) {
BookStore.saveCustomers();
app.showLoginScreen();
}
});
VBox vbox = new VBox();
vbox.setAlignment(Pos.CENTER);
vbox.getChildren().addAll(totalCost, mid, logout);
screen.getChildren().addAll(vbox);
return screen;
}
}