Sushi
Sushi
Sushi
Report On
A Mini-project report submitted in partial fulfillment of the requirements for the award of
the degree of Bachelor of Engineering in Artifical Intelligence and Machine Learning
of Visvesvaraya Technological University, Belgaum.
Submitted by:
CERTIFICATE
This is to certify that the Mini-Project on Calculator For Prefix And Suffix
Expressions”has been successfully carried out by ShashwatYadav(1DT23AI051)
,Akshobhyaks(1DT23AI006) ,Nithin(1DT23AI038) ,Aviral (1DT23AI011),a Bonafide
students of Dayananda Sagar Academy of Technology and Management in partial
fulfilment of the requirements for the award of degree in Bachelor of Engineering in
Artificial Intelligence and Machine Learning of the Visvesvaraya Technological
University, Belgaum during academic year 2024. It is certified that all
corrections/suggestions indicated for Internal Assessment have been incorporated in the
report deposited in the departmental library.
Signature Signature
It gives us immense pleasure to present before you our project titled “Calculator For
Prefix And Suffix Expressions” The joy and satisfaction that go with the successful
completion of any task would be incomplete without the mention of those who made it
possible. We are glad to express our gratitude towards our prestigious institution
We sincerely acknowledge the guidance and constant encouragement of our mini- project
guide Assistant professor Miss Shamia Aftab, Asst. Professor, Dept of AIML .
We express our deepest gratitude and special thanks to Dr. Sandhya N, Prof &H.O.D,
Dept.Of Artificial Intelligence and Machine Learning, for all her guidance and
encouragement.
By utilizing stack-based algorithms, the application ensures precise and efficient parsing
and computation of expressions, providing a reliable solution for complex calculations.
Users interact with the application through an intuitive interface that allows seamless
input of expressions, selection of the preferred evaluation mode, and instant retrieval of
accurate results. The design emphasizes usability, integrating a visually clean layout with
robust error-handling mechanisms to prevent and address user errors effectively.
The project exemplifies the synergy between data structures and algorithms, showcasing
their application in real-world problem-solving scenarios. Leveraging Java's Swing
library, it delivers a dynamic and interactive desktop application that not only serves as a
practical computational tool but also as an educational resource for learning about
expression evaluation and stack-based processing. This project underscores the potential
of combining algorithmic concepts with Java's rich GUI capabilities to develop functional
and user-friendly software solutions.
TABLE OF CONTENTS
1 INTRODUCTION 1
1.1 Background 1
1.3 Motivation 2
1.4 Objectives 2
2 REQUIREMENTS 4
3 Design 5
3.2 Flowchart 11
4 IMPLEMENTATION 10
4.2 Algorithm 11
5 TESTING 17
7 CONCLUSION AND 27
FUTURE WORK
7.1 Conclusion 27
7.2 Advantages 27
8 BIBLIOGRAPHY 28
INTRODUCTION
1. Background
Mathematical expressions in infix, postfix, and prefix formats are fundamental in fields
like mathematics, computer science, and programming. These formats are integral to
problem-solving, compiler design, and algorithm development. While infix is the most
commonly used form in arithmetic calculations, postfix and prefix are pivotal in stack-
based computations and systems where operator precedence must be explicitly handled.
Manually evaluating such expressions can be prone to human error and time-consuming,
especially for complex expressions. The need for a reliable and user-friendly tool to
evaluate these expressions efficiently has become increasingly significant in educational
and computational contexts.
2. Problem Definition
The problem addressed by this project is the absence of an efficient and user-friendly
system for evaluating mathematical expressions in infix, postfix, and prefix formats.
Currently, the manual calculation of such expressions is prone to errors, requires
significant effort, and demands a deep understanding of operator precedence and
associativity rules.
This project targets several challenges associated with expression evaluation, including:
By addressing these challenges, this project aims to simplify the process of mathematical
expression evaluation, making it accessible and reliable for both students and
professionals.
3. Motivation
Manual System: Existing methods for evaluating mathematical expressions are often
manual and highly time-consuming. These approaches are prone to human error,
especially when dealing with complex expressions involving multiple operators and
parentheses.
4.Objective
The primary objective of this project is to develop a Java-based application for
evaluating mathematical expressions in infix, postfix, and prefix formats using a
graphical user interface (GUI). The system is designed to provide accurate, efficient, and
user-friendly evaluation of expressions to simplify the computational process.
The primary objective of the Expression Evaluator project is to automate and simplify the
process of evaluating mathematical expressions in infix, postfix, and prefix formats. This
Java-based GUI application is designed to handle various scenarios encountered in
expression evaluation while providing an intuitive interface for users.
The requirements for the Expression Evaluator project can be categorized into hardware
and software requirements. The hardware requirements specify the minimum system
configuration needed to run the application, while the software requirements outline the
essential tools and technologies required to build and execute the project.
FLOWCHART
CHAPTER 4
IMPLEMENTATION
The implementation chapter describes the design, structure, and components involved in
building the Simple Calculator project in Java. This chapter outlines the different
modules and their functionality, focusing on the core aspects of the program, from user
interaction to the logic behind the calculator.Admin Module
4.2 ALGORITHM
public class h {
public static void main(String[] args) {
JFrame frame = new JFrame("Expression Evaluator");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 400);
evaluateButton.addActionListener((ActionEvent e) -> {
String expression = inputField.getText().trim();
String mode = (String) modeSelector.getSelectedItem();
if (expression.isEmpty()) {
outputArea.setText("Please enter an expression.");
return;
}
try {
double result = switch (mode) {
case "Postfix" -> evaluatePostfix(expression);
case "Prefix" -> evaluatePrefix(expression);
case "Infix" -> evaluateInfix(expression);
default -> 0;
};
outputArea.setText("Result: " + result);
} catch (Exception ex) {
outputArea.setText("Error: Invalid Expression");
}
});
frame.setVisible(true);
}
if (Character.isDigit(c) || c == '.') {
StringBuilder sb = new StringBuilder();
while (i < expr.length() && (Character.isDigit(expr.charAt(i)) || expr.charAt(i)
== '.')) {
sb.append(expr.charAt(i++));
}
i--; // Step back one character to avoid skipping the last digit
values.push(Double.parseDouble(sb.toString()));
} else if (c == '(') {
ops.push(c);
} else if (c == ')') {
while (ops.peek() != '(') {
values.push(applyOp(ops.pop(), values.pop(), values.pop()));
}
ops.pop(); // Remove '(' from stack
} else if ("+-*/^".indexOf(c) != -1) {
while (!ops.isEmpty() && precedence(ops.peek()) >= precedence(c)) {
values.push(applyOp(ops.pop(), values.pop(), values.pop()));
}
ops.push(c);
}
}
while (!ops.isEmpty()) {
values.push(applyOp(ops.pop(), values.pop(), values.pop()));
}
return values.pop();
}
TESTING
Input: 3 + 5 * (2 - 8) / 2 (Infix)
Expected Output: -12
Result: Pass
Input: 2 3 + 4 * (Postfix)
Expected Output: 20
Result: Pass
Input: + 2 * 3 - 4 5 (Prefix)
Expected Output: 1
Result: Pass
Input: ((8 / 4) + (3 ^ 2)) * 2 (Infix)
Expected Output: 22
Result: Pass
Input: 6 3 - 2 + * (Postfix)
Expected Output: Error message "Invalid expression"
Result: Pass
Input: - 10 / 15 (Prefix)
Expected Output: 1
Result: Pass
Input: (2 + 3) * ((4 / 2) (Infix)
Expected Output: Error message "Invalid expression: missing parenthesis"
Result: Pass
Input: 5 2 3 * + (Postfix)
Expected Output: 11
Result: Pass
Input: * + 5 6 - 7 (Prefix)
Expected Output: Error message "Invalid expression: missing operand"
Result: Pass
Input: (10 + (2 * 3)) / 0 (Infix)
Expected Output: Error message "Cannot divide by zero"
Result: Pass
Bug 2: The clear button was not resetting the display properly. This
was fixed by modifying the event listener for the "C" button.
1. Accuracy:
2. Error Handling:
3. User Interface:
4. Performance:
5. Testing Outcome:
6. Key Achievements:
7.1 CONCLUSION
The Simple Calculator project serves as an efficient, reliable, and easy-to-use tool for
basic arithmetic calculations. It automates the process of performing addition, subtraction,
multiplication, and division, reducing the chances of human error. The project was
designed to be simple and intuitive, ensuring that users can quickly learn how to use it.
The system was tested rigorously and confirmed to be functional, with appropriate error
handling for edge cases such as division by zero. This project has met its objectives,
providing a fast, user-friendly calculator that performs essential operations seamlessly.
7.2 ADVANTAGES
The Simple Calculator application has the following advantages:
♦ Fast: The calculator performs calculations instantaneously, with minimal delay.
♦ Efficient: All arithmetic operations are carried out accurately and quickly, ensuring
reliable results.
♦ Reliable: With thorough testing, the calculator proves to be dependable in all tested
scenarios.
♦ Avoids Human Error: The calculator eliminates manual computation errors, providing
accurate results.
♦ User-friendly: The simple interface makes it easy for users of all technical
backgrounds to use.
♦ Error Handling: The application effectively handles division by zero and other invalid
operations.
♦ Accessibility: The application can be easily extended with additional features such as
scientific operations if needed in the future.
With these enhancements, the Simple Calculator can become a more comprehensive tool
for users in various fields, from education to engineering, providing a reliable and
efficient solution for all types of calculations.
CHAPTER 8
BIBLIOGRAPHY
USN: 1DT20AI051
EMAIL-ID: 1dt23ai051@dsatm.edu.in
USN: IDT20AI011
EMAIL-ID: 1dt23ai011@dsatm.edu.in
NAME: Akshobhya
USN: IDT20AI006
EMAIL-ID: 1dt23ai006@dsatm.edu.in
USN: IDT20AI038
EMAIL-ID: 1dt23ai038@dsatm.edu.in