Aditya PDF
Aditya PDF
I affirm that:
1. The contents of this project report are original and have not been
submitted, in part or in whole, for any other degree or qualification.
2. Any sources of information used in this project report have been
properly acknowledged and referenced.
3. The experiments, analyses, and findings presented in this report
are genuine and have not been manipulated or falsified in any
manner.
4. Any assistance received from individuals or institutions during the
course of this project has been duly acknowledged.
Aditya Srivastava
Date:
PROJECT REPORT:
JAVA CALCULATOR APPLICATION
Introduction:
The Java Calculator Application is a simple desktop-based
calculator developed using Java programming language. The
purpose of this application is to perform basic arithmetic
calculations such as addition, subtraction, multiplication, and
division, along with additional functionalities like calculating square,
square root, cube, and cube root of a number. The application
provides a graphical user interface (GUI) for ease of use.
Features:
1. Basic Arithmetic Operations: Addition, Subtraction,
Multiplication, and Division.
2. Additional Functions: Square, Square Root, Cube, and Cube
Root.
3. Error Handling: Proper error handling for invalid input
expressions.
4. Graphical User Interface: Utilizes AWT (Abstract Window
Toolkit) for GUI components.
HARDWARE AND SOFTWARE
REQUIREMENTS
1.Hardware Requirements:
a. Processor: Any modern processor capable of running Java
applications, such as Intel Core series or AMD Ryzen series.
b. Memory (RAM): At least 512 MB of RAM. However, having 1
GB or more is recommended for optimal performance.
c. Storage: Minimal storage space required for the application
files. A few megabytes should suffice.
2.Software Requirements:
a. Operating System: The Java Calculator Application is platform-
independent and can run on any operating system that supports
Java, including:
i) Windows (Windows 7 or later)
ii) MacOS (OS X 10.7 or later)
iii) Linux/Unix-based systems
b. Java Runtime Environment (JRE):
i) The application requires a Java Runtime Environment (JRE)
installed on the system to execute Java programs.
ii) Recommended JRE version: Java SE 8 or later. However,
compatibility may extend to earlier versions depending on
the features used in the application.
PROJECT SCOPE
import java.awt.*;
import java.awt.event.*;
public CalculatorFrame() {
setTitle("Calculator");
setSize(500, 700);
setBackground(new Color(0, 20, 40)); // Set background
color to blackish blue
setResizable(false);
setLayout(new BorderLayout());
String[] buttonLabels = {
"7", "8", "9", "/",
"4", "5", "6", "*",
"1", "2", "3", "-",
"0", ".", "=", "+",
"(", ")", "C", "<-", // Added backspace button
"x^2", "sqrt", "x^3", "cbrt" // Added square, square root,
cube, and cube root buttons
};
for (String label : buttonLabels) {
Button button = new Button(label);
button.addActionListener(new ButtonClickListener());
button.setFont(new Font("Arial", Font.PLAIN, 18)); //
Increase button font size
button.setBackground(new Color(0, 20, 40)); // Set
background color to blackish blue
button.setForeground(Color.WHITE); // Set text
color to white
buttonPanel.add(button);
}
add(buttonPanel, BorderLayout.CENTER);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent
windowEvent) {
System.exit(0);
}
});
}
private class ButtonClickListener implements
ActionListener {
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
if (command.equals("=")) {
calculate();
} else if (command.equals("C")) {
clearAll();
} else if (command.equals("<-")) {
backspace();
} else if (command.equals("x^2")) {
square();
} else if (command.equals("sqrt")) {
squareRoot();
} else if (command.equals("x^3")) {
cube();
} else if (command.equals("cbrt")) {
cubeRoot();
} else if (command.equals("(") || command.equals(")"))
{
display.setText(display.getText() + command);
} else {
display.setText(display.getText() + command);
}
}
void nextChar() {
ch = (++pos < expression.length()) ?
expression.charAt(pos) : -1;
}
double parse() {
nextChar();
double x = parseExpression();
if (pos < expression.length()) throw new
RuntimeException("Unexpected: " + (char) ch);
return x;
}
double parseExpression() {
double x = parseTerm();
for (;;) {
if (eat('+')) x += parseTerm();
else if (eat('-')) x -= parseTerm();
else return x;
}
}
double parseTerm() {
double x = parseFactor();
for (;;) {
if (eat('*')) x *= parseFactor();
else if (eat('/')) x /= parseFactor();
else return x;
}
}
double parseFactor() {
if (eat('+')) return parseFactor();
if (eat('-')) return -parseFactor();
double x;
int startPos = this.pos;
if (eat('(')) {
x = parseExpression();
eat(')');
} else if ((ch >= '0' && ch <= '9') || ch == '.') {
while ((ch >= '0' && ch <= '9') || ch == '.')
nextChar();
x=
Double.parseDouble(expression.substring(startPos, this.pos));
} else {
throw new RuntimeException("Unexpected: "
+ (char) ch);
}
return x;
}
}.parse();
}
}
public static void main(String[] args) {
CalculatorFrame calculator = new CalculatorFrame();
calculator.setVisible(true);
}
}
OUTPUT
TESTING
1. Unit Testing:
a. Addition:
Output:
b. Substruction:
Output:
c. Multiplication:
Output:
d. Division:
Output:
e. Square and Square Root:
For example: Number is 112
f. Cube and Cube Root:
For example: Number is 23
2. System Test:
Output:
MAINTENANCE
1. Bug Fixes and Issue Resolution:
- Addressed reported bugs and issues, prioritizing those affecting
core functionalities and user experience.
2. Performance Optimization:
- Conducted performance monitoring and analysis to identify
performance bottlenecks and areas for optimization.
3. Compatibility Updates:
- Stayed up-to-date with Java platform updates and compatibility
requirements.
4. Security Enhancements:
- Reviewed and updated security measures to address potential
vulnerabilities and security threats.
1. https://www.javatpoint.com/calculator-in-java
2. https://github.com/topics/java-calculator
3. https://chatgpt.com/c/465700bd