Uploaded by John

SImple Graphical Calcultaor in Java

advertisement
ACKNOWLEDGEMENT
First of all, I would like to express my gratitude to director of D3dsoftware,who
took confidence in me and provided me with the opportunity to work as an Intern
at Happy Hues Production. I am so thankful to the team and the guidance and I
had a amazing experience being the part of the team.
Successfully completion of any type of project requires help from a number of
persons. I have also taken help from different people for the preparation of this
report. Now there is a little effort to show my deep gratitude to those helpful
personnel.
I convey my sincere gratitude to my Academic supervisor Mr. Surya Bam,
academic adviser of Asian School of Management and Technology. Without his
kind direction and proper guidance this study would have been a little success.
In every phase of the project his supervision and guidance shaped this report to
complete perfection.
ABSTRACT
This report is the full documentation of the project of a application developed
during my internship period. Calculator is an application developed during
internship period at D3dsoftware. Application is made in Java language and use
Java AWT and Java Swing library for gui.
Keywords : JAVA AWT, JAVA SWING,GUI.
1
TABLE OF CONTENT
ACKNOWLEDGEMENT.................................................................................I
ABSTRACT.......................................................................................................I
CHAPTER 1: INTRODUCTION ................................................................... 4
1.1 Introduction ........................................................................................... 4
1.1.1 Introduction to Project ............................................................... 4
1.1.3 Duration ..................................................................................... 4
1.2 Problem Statement ................................................................................ 5
1.3 Objective ............................................................................................... 5
1.4 Responsibilities Assigned ..................................................................... 5
CHAPTER 3 : SYSTEM ANALYSIS ............................................................. 6
3.1 System Requirements............................................................................ 7
3.1.1 Functional Requirements ........................................................... 7
3.1.1.1 Use Case Diagram .................................................................. 7
3.1.2 Non-Functional Requirements ................................................... 8
3.1.2.1 Interface .................................................................................. 8
3.1.2.2 Performance ............................................................................ 9
3.1.2.3 Scalability ............................................................................... 9
3.1.2.4 Usability.................................................................................. 9
3.2 Feasibility Analysis ............................................................................. 10
3.2.1 Economic Analysis .................................................................. 10
3.2.2 Operational Analysis ............................................................... 10
3.2.3 Technical Analysis................................................................... 10
3.3 Software and Hardware Requirement ......................................... 10
3.3.1 Software Requirement ............................................................. 10
3.3.2 Hardware Requirement ............................................................ 11
2
4.4 Interface Design .................................................................................. 11
CHAPTER 5: IMPLEMENTATION AND TESTING ............................... 14
5.1 Implementation ................................................................................... 14
5.1.1 Front End Tools ............................................................................... 14
5.1.1.1 Java AWT(Abstract Window Toolkit ................................... 14
5.1.2 Back End Tools........................................................................ 14
5.1.2.1 Java ....................................................................................... 14
5.2 Development Method.......................................................................... 14
5.2.1 Spiral Model ............................................................................ 14
5.3 Testing................................................................................................. 16
5.3.1 Unit Testing ............................................................................. 16
5.3.2 System Testing......................... Error! Bookmark not defined.
CHAPTER 6:CONCLUSION & LESSON LEARNT................................. 17
6.1 Conclusion .......................................................................................... 17
6.2 Lesson Learnt ...................................................................................... 17
3
CHAPTER 1: INTRODUCTION
1.1 Introduction
1.1.1 Introduction to Project
Almost six hundred thousand students took the GRE from 2012, which is a very
large number. In which most of the students are non-native English speaker and
they should have to learn almost four thousand new vocabulary words. This does
not an easy task to manages the notes for the regular student. So the concept
"Vocabulary" arises. One of the studies shows that nearly 14000 students took
GRE from Nepal and they all have to learn all these vocabulary words, this
mobile application would be very helpful to the learner. For all these reason we
decided to develop this application. In this application, users can easily manage
his/her learning progress and regularly check his/her completed words. In the
admin panel, we provide authorization to edit the words, delete and update new
meaning, and examples. This application would be really helpful to the student.
more. The team believes in being able to work on any platform and thus, seek
for learning the linguistics and core concepts rather than the syntax.
1.1.3 Duration
Table 1.1 Intern Details
Start date:
1st September, 2023
End date:
15 October, 2023
Total duration:
6 Weeks
4
1.2 Problem Statement
The initial survey taken by the company found that students had faced various
kind of problems like finding the authentic words, make a clear notes, to make a
note safe and reusable, portability and many more. We found bachelor’s students
were usually busy outside the home and college so they would not have
comfortable time to read notes and remember the words. So our application
likely to be very useful to the GRE students.
1.3 Objective
The major objective of the project is to develop an Simple Calculator App with
minimalistic design that can improved later by adding new functionalities.
1.4 Responsibilities Assigned
As an intern at D3dsoftware, I was given certain responsibilities to carry out
during internship period. The responsibility involved various task assigned by
my mentor
The main responsibilities that carried out during my internship period in Happy
Hues are as flows.

Research and Analysis of different aspects needed for Application
Development.

System Architecture Design.

System Analysis

Designing Interface

Documentation
5
CHAPTER 2: LITERATURE REVIEW
2.1 Literature Review
The development of calculator applications, especially those implemented in
Java, has been a subject of interest in the realm of software development. As the
computing landscape evolves, the need for efficient and user-friendly calculators
remains paramount. This literature review explores relevant studies and existing
literature related to calculator applications, with a focus on those developed using
the Java programming language.
2.1.1 Calculator Applications: A Historical Perspective
Historically, calculator applications have been fundamental tools in computing.
The evolution of calculators from simple arithmetic devices to sophisticated
software applications reflects the advancements in technology. Early calculators
were standalone devices with limited functionalities, primarily designed for
basic arithmetic operations.
2.1.2 Java in Software Development
Java, known for its portability and platform independence, has been widely
adopted in various domains of software development. Its object-oriented nature,
strong community support, and extensive libraries make it an ideal choice for
developing diverse applications. Java's Write Once, Run Anywhere (WORA)
principle aligns with the demand for cross-platform compatibility.
2.1.3 Relevance of Java in Calculator Development
Java's suitability for developing graphical user interfaces (GUIs) and its ability
to handle mathematical computations efficiently make it well-suited for
calculator application development. Studies have shown that Java-based
6
calculators offer a robust and consistent user experience across different
operating systems.
CHAPTER 3 : SYSTEM ANALYSIS
3.1 System Requirements
A requirement analysis is a description of a prediction system to be developed,
laying out functional and non-functional requirement, and may include a set of
use cases that describes about how system and data manipulate by different
agents. This requirement analysis enlists enough and necessary requirements that
are required for project development. To derive the requirements, clear and
thorough understanding of the system to be developed or being developed is
needed. This is achieved and refined with detailed and continuous
communications with the project team.
3.1.1 Functional Requirements
3.1.1.1 Use Case Diagram
A functional requirement is something a system must do. In this project
functional requirements are:
7
Figure 3.1 Use Case Diagram of System
User can sign up to the app, take vocabulary test for progressing itself , user also
can add to favorite that can review on near future. Admin is responsible for
managing database, API security and data manipulation.
3.1.2 Non-Functional Requirements
The non-functional requirements in content to the project are as follows:
3.1.2.1 Interface
We have user interface design using AWT framework librabry in java.
User easily handles application with its requirements.
Figure below show interface of project:
8
Figure 3.2 Interface of System
3.1.2.2 Performance
This system of is design with highly optimizes code.Performance is best for
normal user.
3.1.2.3 Scalability
The system is develop with Java on backend and React Native is a frontend, we
can further scale this app by adding machine learning approach to recommend
word to the student.
3.1.2.4 Usability
The applications to be developed are built in a user-friendly interface such hat
even a common person can understand it and make the most use of it .
9
3.2 Feasibility Analysis
Feasibility studies aim to objectively and rationally uncover the strengths and
weaknesses of this project or proposed venture, opportunities and threats as
presented by the environment, the resources required to carry for optimum
analysis.
3.2.1 Economic Analysis
This project is totally non-profitable. Students are easily download or browse
through internet to use app.
3.2.2 Operational Analysis
System automatically generates user progress weekly and daily basis. This
system is operationally feasible.
3.2.3 Technical Analysis
All the tools and software product required to construct this project is easily
available in the web. It do not require special environment to execute. It needs
just an window operating system. All these aspects are easily affordable. The
application requires simple user interfaces.
3.3 Software and Hardware Requirement
3.3.1 Software Requirement
Following are the software requirement necessary for the project.

Java Development Kit (JDK) 21

Visual Studio Code (Editor)

Windows (Operating System)
10
3.3.2 Hardware Requirement
Following are the hardware requirement necessary for this project.

Computer Device (Desktop/Laptop)
CHAPTER 4: SYSTEM DESIGN
4.1 System Design
The design phase of the calculator application is a critical step in translating the
conceptual framework into a tangible and functional software system. This
chapter focuses on the system design aspects, encompassing the architecture,
user interface design, modules, and the integration of advanced features.
4.1.1 Architectural Considerations
The architecture of the calculator application is pivotal to its performance and
scalability. Leveraging Java's object-oriented principles, the application adopts
a modular architecture. Each functional component, including digit input,
arithmetic operations, and memory management, is encapsulated within welldefined modules. This modular approach facilitates code maintainability,
reusability, and future scalability.
4.1.2 User Interface Design
User interface design plays a pivotal role in ensuring a seamless and intuitive
user experience. The design follows established principles of user interface (UI)
design, with an emphasis on clarity, consistency, and ease of use. The placement
of digit buttons, operator buttons, and memory functions is carefully considered
to optimize user workflow. The color scheme is chosen for readability and visual
appeal, adhering to best practices in UI design.
11
4.1.3 Module Design
Each module in the calculator application is designed to handle specific
functionalities. The digit input module manages user input, ensuring accurate
and responsive handling of numeric entries. The operator module oversees
arithmetic operations, scientific calculations, and special functions. Memoryrelated operations, including storage and retrieval, are encapsulated within the
memory module. This modular design enhances code organization and facilitates
future enhancements.
4.1.4 Integration of Advanced Features
Advanced features such as square root, reciprocal, and memory functions are
seamlessly integrated into the design. The system design accounts for the logical
flow of these features, ensuring they are easily accessible to users. The
integration is implemented in a manner that maintains the overall simplicity of
the calculator while providing users with powerful and versatile functionalities.
4.1.5 Error Handling and Validation
Effective error handling and input validation are integral aspects of the system
design. The application incorporates mechanisms to validate user inputs,
preventing erroneous entries. Clear and informative error messages are
implemented to guide users in cases of invalid input or computational errors.
This approach enhances the overall robustness and user-friendliness of the
calculator.
4.1.6 Memory Management Design
The memory management design focuses on efficient storage and retrieval of
values. The memory module is designed to handle various memory-related
operations, including clearing memory, recalling stored values, and adding to the
12
memory. The design ensures that memory operations are executed accurately and
do not compromise the overall performance of the calculator.
4.1.7 Security Considerations
While the calculator application primarily deals with non-sensitive data, security
considerations are implemented at a basic level. The design accounts for input
validation to prevent potential security vulnerabilities arising from user inputs.
Future iterations may explore enhanced security measures if deemed necessary.
13
CHAPTER 5: IMPLEMENTATION AND TESTING
5.1 Implementation
The Implementation strategy includes development, testing, and deployment
based on project planning activities and deliverables. Development for the
system included creating the system design, and creating plans on how the
implement each system. The intern used JAVAlanguage coding aspect of the
implementation for the project. Testing is performed to help ensure the product
and/or service is ready to be operationalized and commercialized. For the testing
portion of implementation of the system the intern used unit testing, functional
testing
and
user
testing
methods.
5.1.1 Front End Tools
5.1.1.1 Java AWT(Abstract Window Toolkit
Thee choice of Java as the programming language ensures portability and ease
of development. AWT is employed for creating a robust and responsive user
interface.
5.1.2 Back End Tools
5.1.2.1 Java
The choice of Java as the programming language ensures portability and ease
of development. AWT is employed for creating a robust and responsive user
interface.
5.2 Development Method
5.2.1 Spiral Model
This project was develop using spiral development technique allow flexibility
and interactivity into development process of app.
14
Design: Here you define the feature to develop in next cycle.
Implement:Here it’s where you develop the feature that you decide in the
Design phase.
User Experience: Here ti’s where you make sure that what you’ve made its best
experiences of app user.
Evaluate: Final thoughts about what you’ve done right and wrong during the
past cycle, forming a new set of observation and go back to first step.
Figure 5.2 Spiral Model for Development
15
1
5.3 Testing
The testing phase is a crucial component in the software development lifecycle,
ensuring the reliability, functionality, and performance of the Java-based
calculator application. This chapter details the testing methodologies employed,
evaluates the application against predefined criteria, and discusses the
outcomes of the testing process.
5.3.1 Unit Testing
In unit testing we perform individual function testing like +, - , * , / .etc
Addition of 6 and 8
Figure 5.3 Test Cases of System
16
CHAPTER 6: CONCLUSION & LESSON LEARNT
6.1 Conclusion
The internship program has been an excellent and rewarding experience for the
author. It has provided author with the opportunity to develop understanding of
real world working environment as well as establish network contact with
different personnel from the IT industry. During internship author learn all about
Java App development.
6.2 Lesson Learnt
Six weeks in d3dsoftware as an intern, was an invaluable experience. This was
one great opportunity for the intern to learn in a professional environment. The
internship has helped the intern to learn in a professional environment. It also,
helped the intern to improve their practical skills, knowledge, abilities and to
work in a team. One important lesson learned by intern was “Think as a user not
as the seller as we develop everything to facilitate the users”.
17
SOURCE CODE
File Name : MainClass.java
import javax.swing.*;
public class MainClass
{
public static void main(String[] args)
{
new Calculator();
}
}
File
Name
:
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Calculator implements ActionListener {
double number, answer;
int calculation;
JFrame frame;
JLabel label = new JLabel();
JTextField textField = new JTextField();
18
Calculator.java
JRadioButton onRadioButton = new JRadioButton("on");
JRadioButton offRadioButton = new JRadioButton("off");
JButton buttonZero = new JButton("0");
JButton buttonOne = new JButton("1");
JButton buttonTwo = new JButton("2");
JButton buttonThree = new JButton("3");
JButton buttonFour = new JButton("4");
JButton buttonFive = new JButton("5");
JButton buttonSix = new JButton("6");
JButton buttonSeven = new JButton("7");
JButton buttonEight = new JButton("8");
JButton buttonNine = new JButton("9");
JButton buttonDot = new JButton(".");
JButton buttonClear = new JButton("C");
JButton buttonDelete = new JButton("DEL");
JButton buttonEqual = new JButton("=");
JButton buttonMul = new JButton("x");
JButton buttonDiv = new JButton("/");
JButton buttonPlus = new JButton("+");
JButton buttonMinus = new JButton("-");
JButton buttonSquare = new JButton("x\u00B2");
JButton buttonReciprocal = new JButton("1/x");
JButton buttonSqrt = new JButton("\u221A");
;
Calculator() {
prepareGUI();
19
addComponents();
addActionEvent();
}
public void prepareGUI() {
frame = new JFrame();
frame.setTitle("Calculator");
frame.setSize(300, 490);
frame.getContentPane().setLayout(null);
frame.getContentPane().setBackground(new Color(135, 206, 250));
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void addComponents() {
label.setBounds(250, 0, 50, 50);
label.setForeground(Color.white);
frame.add(label);
textField.setBounds(10, 40, 270, 40);
textField.setFont(new Font("Arial", Font.BOLD, 20));
textField.setEditable(false);
textField.setHorizontalAlignment(SwingConstants.RIGHT);
frame.add(textField);
20
onRadioButton.setBounds(10, 95, 60, 40);
onRadioButton.setSelected(true);
onRadioButton.setFont(new Font("Arial", Font.BOLD, 14));
onRadioButton.setBackground(Color.black);
onRadioButton.setForeground(Color.white);
frame.add(onRadioButton);
offRadioButton.setBounds(10, 120, 60, 40);
offRadioButton.setSelected(false);
offRadioButton.setFont(new Font("Arial", Font.BOLD, 14));
offRadioButton.setBackground(Color.black);
offRadioButton.setForeground(Color.white);
frame.add(offRadioButton);
ButtonGroup buttonGroup = new ButtonGroup();
buttonGroup.add(onRadioButton);
buttonGroup.add(offRadioButton);
buttonSeven.setBounds(10, 230, 60, 40);
buttonSeven.setFont(new Font("Arial", Font.BOLD, 20));
frame.add(buttonSeven);
buttonEight.setBounds(80, 230, 60, 40);
buttonEight.setFont(new Font("Arial", Font.BOLD, 20));
frame.add(buttonEight);
buttonNine.setBounds(150, 230, 60, 40);
21
buttonNine.setFont(new Font("Arial", Font.BOLD, 20));
frame.add(buttonNine);
buttonFour.setBounds(10, 290, 60, 40);
buttonFour.setFont(new Font("Arial", Font.BOLD, 20));
frame.add(buttonFour);
buttonFive.setBounds(80, 290, 60, 40);
buttonFive.setFont(new Font("Arial", Font.BOLD, 20));
frame.add(buttonFive);
buttonSix.setBounds(150, 290, 60, 40);
buttonSix.setFont(new Font("Arial", Font.BOLD, 20));
frame.add(buttonSix);
buttonOne.setBounds(10, 350, 60, 40);
buttonOne.setFont(new Font("Arial", Font.BOLD, 20));
frame.add(buttonOne);
buttonTwo.setBounds(80, 350, 60, 40);
buttonTwo.setFont(new Font("Arial", Font.BOLD, 20));
frame.add(buttonTwo);
buttonThree.setBounds(150, 350, 60, 40);
buttonThree.setFont(new Font("Arial", Font.BOLD, 20));
frame.add(buttonThree);
22
buttonDot.setBounds(150, 410, 60, 40);
buttonDot.setFont(new Font("Arial", Font.BOLD, 20));
frame.add(buttonDot);
buttonZero.setBounds(10, 410, 130, 40);
buttonZero.setFont(new Font("Arial", Font.BOLD, 20));
frame.add(buttonZero);
buttonEqual.setBounds(220, 350, 60, 100);
buttonEqual.setFont(new Font("Arial", Font.BOLD, 20));
buttonEqual.setBackground(new Color(239, 188, 2));
frame.add(buttonEqual);
buttonDiv.setBounds(220, 110, 60, 40);
buttonDiv.setFont(new Font("Arial", Font.BOLD, 20));
buttonDiv.setBackground(new Color(239, 188, 2));
frame.add(buttonDiv);
buttonSqrt.setBounds(10, 170, 60, 40);
buttonSqrt.setFont(new Font("Arial", Font.BOLD, 18));
frame.add(buttonSqrt);
buttonMul.setBounds(220, 230, 60, 40);
buttonMul.setFont(new Font("Arial", Font.BOLD, 20));
buttonMul.setBackground(new Color(239, 188, 2));
frame.add(buttonMul);
23
buttonMinus.setBounds(220, 170, 60, 40);
buttonMinus.setFont(new Font("Arial", Font.BOLD, 20));
buttonMinus.setBackground(new Color(239, 188, 2));
frame.add(buttonMinus);
buttonPlus.setBounds(220, 290, 60, 40);
buttonPlus.setFont(new Font("Arial", Font.BOLD, 20));
buttonPlus.setBackground(new Color(239, 188, 2));
frame.add(buttonPlus);
buttonSquare.setBounds(80, 170, 60, 40);
buttonSquare.setFont(new Font("Arial", Font.BOLD, 20));
frame.add(buttonSquare);
buttonReciprocal.setBounds(150, 170, 60, 40);
buttonReciprocal.setFont(new Font("Arial", Font.BOLD, 15));
frame.add(buttonReciprocal);
buttonDelete.setBounds(150, 110, 60, 40);
buttonDelete.setFont(new Font("Arial", Font.BOLD, 12));
buttonDelete.setBackground(Color.red);
buttonDelete.setForeground(Color.white);
frame.add(buttonDelete);
buttonClear.setBounds(80, 110, 60, 40);
buttonClear.setFont(new Font("Arial", Font.BOLD, 12));
buttonClear.setBackground(Color.red);
24
buttonClear.setForeground(Color.white);
frame.add(buttonClear);
}
public void addActionEvent() {
onRadioButton.addActionListener(this);
offRadioButton.addActionListener(this);
buttonClear.addActionListener(this);
buttonDelete.addActionListener(this);
buttonDiv.addActionListener(this);
buttonSqrt.addActionListener(this);
buttonSquare.addActionListener(this);
buttonReciprocal.addActionListener(this);
buttonMinus.addActionListener(this);
buttonSeven.addActionListener(this);
buttonEight.addActionListener(this);
buttonNine.addActionListener(this);
buttonMul.addActionListener(this);
buttonFour.addActionListener(this);
buttonFive.addActionListener(this);
buttonSix.addActionListener(this);
buttonPlus.addActionListener(this);
buttonOne.addActionListener(this);
buttonTwo.addActionListener(this);
buttonThree.addActionListener(this);
buttonEqual.addActionListener(this);
25
buttonZero.addActionListener(this);
buttonDot.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (source == onRadioButton) {
enable();
} else if (source == offRadioButton) {
disable();
} else if (source == buttonClear) {
label.setText("");
textField.setText("");
} else if (source == buttonDelete) {
int length = textField.getText().length();
int number = length - 1;
if (length > 0) {
StringBuilder back = new StringBuilder(textField.getText());
back.deleteCharAt(number);
textField.setText(back.toString());
}
26
if (textField.getText().endsWith("")) {
label.setText("");
}
} else if (source == buttonZero) {
if (textField.getText().equals("0")) {
return;
} else {
textField.setText(textField.getText() + "0");
}
} else if (source == buttonOne) {
textField.setText(textField.getText() + "1");
} else if (source == buttonTwo) {
textField.setText(textField.getText() + "2");
} else if (source == buttonThree) {
textField.setText(textField.getText() + "3");
} else if (source == buttonFour) {
textField.setText(textField.getText() + "4");
} else if (source == buttonFive) {
textField.setText(textField.getText() + "5");
} else if (source == buttonSix) {
textField.setText(textField.getText() + "6");
} else if (source == buttonSeven) {
textField.setText(textField.getText() + "7");
} else if (source == buttonEight) {
textField.setText(textField.getText() + "8");
} else if (source == buttonNine) {
textField.setText(textField.getText() + "9");
27
} else if (source == buttonDot) {
if (textField.getText().contains(".")) {
return;
} else {
textField.setText(textField.getText() + ".");
}
} else if (source == buttonPlus) {
String str = textField.getText();
number = Double.parseDouble(textField.getText());
textField.setText("");
label.setText(str + "+");
calculation = 1;
} else if (source == buttonMinus) {
String str = textField.getText();
number = Double.parseDouble(textField.getText());
textField.setText("");
label.setText(str + "-");
calculation = 2;
} else if (source == buttonMul) {
String str = textField.getText();
number = Double.parseDouble(textField.getText());
textField.setText("");
label.setText(str + "X");
calculation = 3;
} else if (source == buttonDiv) {
String str = textField.getText();
28
number = Double.parseDouble(textField.getText());
textField.setText("");
label.setText(str + "/");
calculation = 4;
} else if (source == buttonSqrt) {
number = Double.parseDouble(textField.getText());
Double sqrt = Math.sqrt(number);
textField.setText(Double.toString(sqrt));
} else if (source == buttonSquare) {
String str = textField.getText();
number = Double.parseDouble(textField.getText());
double square = Math.pow(number, 2);
String string = Double.toString(square);
if (string.endsWith(".0")) {
textField.setText(string.replace(".0", ""));
} else {
textField.setText(string);
}
label.setText("(sqr)" + str);
} else if (source == buttonReciprocal) {
number = Double.parseDouble(textField.getText());
double reciprocal = 1 / number;
String string = Double.toString(reciprocal);
if (string.endsWith(".0")) {
textField.setText(string.replace(".0", ""));
} else {
29
textField.setText(string);
}
} else if (source == buttonEqual) {
switch (calculation) {
case 1:
answer = number + Double.parseDouble(textField.getText());
if (Double.toString(answer).endsWith(".0")) {
textField.setText(Double.toString(answer).replace(".0", ""));
} else {
textField.setText(Double.toString(answer));
}
label.setText("");
break;
case 2:
answer = number - Double.parseDouble(textField.getText());
if (Double.toString(answer).endsWith(".0")) {
textField.setText(Double.toString(answer).replace(".0", ""));
} else {
textField.setText(Double.toString(answer));
}
label.setText("");
break;
case 3:
answer = number * Double.parseDouble(textField.getText());
if (Double.toString(answer).endsWith(".0")) {
textField.setText(Double.toString(answer).replace(".0", ""));
} else {
30
textField.setText(Double.toString(answer));
}
label.setText("");
break;
case 4:
answer = number / Double.parseDouble(textField.getText());
if (Double.toString(answer).endsWith(".0")) {
textField.setText(Double.toString(answer).replace(".0", ""));
} else {
textField.setText(Double.toString(answer));
}
label.setText("");
break;
}
}
}
public void enable() {
onRadioButton.setEnabled(false);
offRadioButton.setEnabled(true);
textField.setEnabled(true);
label.setEnabled(true);
buttonClear.setEnabled(true);
buttonDelete.setEnabled(true);
31
buttonDiv.setEnabled(true);
buttonSqrt.setEnabled(true);
buttonSquare.setEnabled(true);
buttonReciprocal.setEnabled(true);
buttonMinus.setEnabled(true);
buttonSeven.setEnabled(true);
buttonEight.setEnabled(true);
buttonNine.setEnabled(true);
buttonMul.setEnabled(true);
buttonFour.setEnabled(true);
buttonFive.setEnabled(true);
buttonSix.setEnabled(true);
buttonPlus.setEnabled(true);
buttonOne.setEnabled(true);
buttonTwo.setEnabled(true);
buttonThree.setEnabled(true);
buttonEqual.setEnabled(true);
buttonZero.setEnabled(true);
buttonDot.setEnabled(true);
}
public void disable() {
onRadioButton.setEnabled(true);
offRadioButton.setEnabled(false);
textField.setText("");
label.setText(" ");
32
buttonClear.setEnabled(false);
buttonDelete.setEnabled(false);
buttonDiv.setEnabled(false);
buttonSqrt.setEnabled(false);
buttonSquare.setEnabled(false);
buttonReciprocal.setEnabled(false);
buttonMinus.setEnabled(false);
buttonSeven.setEnabled(false);
buttonEight.setEnabled(false);
buttonNine.setEnabled(false);
buttonMul.setEnabled(false);
buttonFour.setEnabled(false);
buttonFive.setEnabled(false);
buttonSix.setEnabled(false);
buttonPlus.setEnabled(false);
buttonOne.setEnabled(false);
buttonTwo.setEnabled(false);
buttonThree.setEnabled(false);
buttonEqual.setEnabled(false);
buttonZero.setEnabled(false);
buttonDot.setEnabled(false);
}
}
33
Download