0% found this document useful (0 votes)
3 views

oops assignment 2 solution

The document outlines the design and implementation of a calculator application using JavaFX, emphasizing its contribution to Sustainable Development Goal 11 (SDG 11) focused on sustainable cities and communities. It highlights the benefits of reducing electronic waste, improving resource management, and promoting energy efficiency through software-based tools. The conclusion suggests further enhancements to the application and increased awareness of digital tools to support sustainable practices.

Uploaded by

pradeeplavrp09
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

oops assignment 2 solution

The document outlines the design and implementation of a calculator application using JavaFX, emphasizing its contribution to Sustainable Development Goal 11 (SDG 11) focused on sustainable cities and communities. It highlights the benefits of reducing electronic waste, improving resource management, and promoting energy efficiency through software-based tools. The conclusion suggests further enhancements to the application and increased awareness of digital tools to support sustainable practices.

Uploaded by

pradeeplavrp09
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Elaborate Solution: Creating a Calculator Application in JavaFX and Its

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

Calculator Application in JavaFX: A calculator application is a simple yet practical


software tool that performs arithmetic operations like addition, subtraction, multiplication,
and division. Implementing this in JavaFX, a powerful framework for building rich client
applications, allows us to create a user-friendly interface.

SDG 11 (Sustainable Cities and Communities): Sustainable Development Goal 11 aims to


make cities inclusive, safe, resilient, and sustainable. It focuses on creating urban
environments that support economic development, reduce environmental impact, and provide
better quality of life for residents.

Design and Implementation of Calculator Application

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;

public class CalculatorApp extends Application {

private TextField display;

@Override
public void start(Stage primaryStage) {
display = new TextField();
display.setEditable(false);

GridPane grid = new GridPane();


grid.add(display, 0, 0, 4, 1);

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++;
}
}

Scene scene = new Scene(grid, 300, 400);


primaryStage.setTitle("Calculator");
primaryStage.setScene(scene);
primaryStage.show();
}

private void handleButtonPress(String label) {


switch (label) {
case "C":
display.clear();
break;
case "=":
calculateResult();
break;
default:
display.appendText(label);
break;
}
}

private void calculateResult() {


try {
String result = evaluateExpression(display.getText());
display.setText(result);
} catch (Exception e) {
display.setText("Error");
}
}

private String evaluateExpression(String expression) {


// Simple evaluation logic (can be replaced with a more robust
solution)
return Double.toString(new
ScriptEngineManager().getEngineByName("JavaScript").eval(expression));
}

public static void main(String[] args) {


launch(args);
}
}

Impact Analysis

Contribution to Sustainability:

1. Reducing Electronic Waste: By using software-based calculators, we reduce the


demand for physical calculators, which leads to a decrease in electronic waste.
2. Resource Management: Software tools like calculators help in efficient resource
management and planning, crucial for sustainable urban development.
3. Energy Efficiency: Digital calculators consume less energy compared to
manufacturing and disposing of physical calculators.

Potential Benefits:

 Environmental Benefits: Lower production and disposal impact on the environment.


 Economic Benefits: Cost savings from not needing to purchase physical calculators.
 Social Benefits: Easy access to calculation tools, supporting education and
professional work.

Footprints and Handprints of SDG 11

Footprint (Negative Impact):

oPhysical Calculators: Production, usage, and disposal of physical calculators


contribute to electronic waste and resource depletion.
o Environmental Degradation: Mining for raw materials and manufacturing
processes have environmental impacts.
2. Handprint (Positive Impact):
o Digital Tools: Implementing digital tools reduces the environmental footprint
of manufacturing and disposing of physical calculators.
o Sustainable Practices: Encourages the use of sustainable practices in daily
activities, contributing to the broader goals of SDG 11.

Conclusion (1 mark)

Summary:

 Developing a calculator application in JavaFX not only demonstrates technical


proficiency but also supports the sustainability goals of SDG 11.
 By reducing reliance on physical calculators, we can minimize electronic waste and
contribute to more sustainable urban environments.

Recommendations:

 Enhancement: Further enhance the application by adding more features like


scientific calculations, which can further reduce the need for specialized physical
calculators.
 Awareness: Increase awareness about the benefits of using digital tools to promote
sustainable practices in urban settings.
Broader Implications:

 Integration: Integrating more digital solutions in urban management can significantly


contribute to achieving SDG 11.
 Innovation: Encouraging innovation in digital solutions supports the development of
smart, sustainable cities and communities.

You might also like