Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

help me fix this javafx program: main class: import javafx.application.Application; import javafx.fxml . FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage; import java.io . IOException; public

help me fix this javafx program:
main class:
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.IOException;
public class CloudCostMonitor extends Application {
@Override
public void start(Stage stage) throws Exception {
Parent root =
FXMLLoader.load(getClass().getResource("CloudCostMonitor.fxml"));
Scene scene = new Scene(root); // attach scene graph to scene
stage.setTitle("Cloud Cost Monitor"); // displayed in window's title bar
stage.setScene(scene); // attach scene to stage
stage.show(); // display the stage
}
public static void main(String[] args){
// create a TipCalculator object and call its start method
launch(args);
}
}
controller class
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.DatePicker;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import java.time.Duration;
import java.time.LocalDate;
public class CloudCostController {
@FXML
private TextField costTextField;
@FXML
private TextField monthlyCostTextField;
@FXML
private TextField usageTextField;
@FXML
private TextField alertTextField;
@FXML
private RadioButton dropboxRadioButton;
@FXML
private DatePicker durationDatePicker;
@FXML
private Button enterButton;
@FXML
private RadioButton googleRadioButton;
@FXML
private RadioButton onedriveRadioButton;
@FXML
private ToggleGroup providerGroup;
@FXML
private TextField storageTextField;
private final double DROPBOX_RATE_PER_GB =0.02;
private final double GOOGLE_RATE_PER_GB =0.01;
private final double ONEDRIVE_RATE_PER_GB =0.015;
private final double STORAGE_LIMIT_GB =100; // Example limit, you can change it
@FXML
void initialize(){
// Set today's date as the default for the durationDatePicker
durationDatePicker.setValue(LocalDate.now());
// Set a default cloud provider as selected. For instance, select Google Drive by default.
googleRadioButton.setSelected(true);
// Clear all text fields to be cleared or set to a default value at startup:
costTextField.clear();
monthlyCostTextField.clear();
usageTextField.clear();
alertTextField.clear();
storageTextField.clear();
}
@FXML
void calculateButtonPressed(ActionEvent event){
LocalDate startDate = durationDatePicker.getValue();
LocalDate endDate = LocalDate.now(); // Assume end date is today
long days = Duration.between(startDate.atStartOfDay(), endDate.atStartOfDay()).toDays();
double storageUsed = Double.parseDouble(storageTextField.getText());
double costPerDay =0;
// Determine the selected provider and calculate the cost
if (dropboxRadioButton.isSelected()){
costPerDay = DROPBOX_RATE_PER_GB * storageUsed;
} else if (googleRadioButton.isSelected()){
costPerDay = GOOGLE_RATE_PER_GB * storageUsed;
} else if (onedriveRadioButton.isSelected()){
costPerDay = ONEDRIVE_RATE_PER_GB * storageUsed;
}
double totalCost = costPerDay * days;
double monthlyCost = totalCost *30; // Assuming 30 days in a month
costTextField.setText(String.format("$%.2f", costPerDay));
monthlyCostTextField.setText(String.format("$%.2f", monthlyCost));
if (storageUsed > STORAGE_LIMIT_GB){
alertTextField.setText("Warning: Approaching storage limit!");
// You can also display an alert dialog
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.setTitle("Storage Limit Warning");
alert.setHeaderText("Warning: Approaching storage limit!");
alert.setContentText("You have exceeded your storage limit of "+ STORAGE_LIMIT_GB +" GB.");
alert.showAndWait();
} else {
alertTextField.clear();
}
}
}
here's the FXML file just incase:
?xml version="1.0" encoding="UTF-8"?>

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_2

Step: 3

blur-text-image_3

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

Graph Databases

Authors: Ian Robinson, Jim Webber, Emil Eifrem

1st Edition

1449356265, 978-1449356262

More Books

Students also viewed these Databases questions

Question

Determine miller indices of plane A Z a/2 X a/2 a/2 Y

Answered: 1 week ago

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago