oops assignment 2 solution
oops assignment 2 solution
Impact on SDG 11
The aim of this assignment is to design and implement a calculator application using JavaFX,
while exploring how such applications can contribute to Sustainable Development Goal 11
(SDG 11) - Sustainable Cities and Communities.
Introduction
Design Process:
Layout: Use JavaFX layouts like GridPane to organize buttons and display.
o
Controls: Use JavaFX controls like Buttons and TextField for user
o
interaction.
o Events: Handle button click events to perform arithmetic operations.
2. Key Features:
o Basic Operations: Addition, subtraction, multiplication, and division.
o User-Friendly Interface: Clear and intuitive layout.
o Real-time Calculation: Immediate display of results.
o
Code Implementation:
java
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
@Override
public void start(Stage primaryStage) {
display = new TextField();
display.setEditable(false);
String[] buttonLabels = {
"7", "8", "9", "/",
"4", "5", "6", "*",
"1", "2", "3", "-",
"0", "C", "=", "+"
};
int row = 1;
int col = 0;
for (String label : buttonLabels) {
Button button = new Button(label);
button.setOnAction(e -> handleButtonPress(label));
grid.add(button, col, row);
col++;
if (col == 4) {
col = 0;
row++;
}
}
Impact Analysis
Contribution to Sustainability:
Potential Benefits:
Conclusion (1 mark)
Summary:
Recommendations: