Sunteți pe pagina 1din 11

Table of Contents

1 Introduction..............................................................................................................................2

2 Hardware Requirements..........................................................................................................2

3 UML Class Diagram................................................................................................................2

4 Class Diagram for calculator assignment................................................................................3

5 Interface Diagram....................................................................................................................3

6 Learning Objectives.................................................................................................................4

6.1 Understanding the Calculator Application........................................................................4

6.2 Creating the Calculator Application.................................................................................5

6.3 Code for the Calculator Application.................................................................................6

7 Implementation........................................................................................................................7

8 Output....................................................................................................................................10

1
1 Introduction

In this Program we are making a standard calculator that performs addition, subtraction,
multiplication and division based on the user input. The program takes the value of both the
numbers (entered by user) and then user is asked to enter the operation (+, -,*, / ,M+,M-,MS),
based on the input program performs the selected operation on the entered numbers using by java
Application.

2 Hardware Requirements

 Processor: Minimum: 1.4 GHz 64-bit Processor


 Hard disk: 250GB hard drive Random Access
 Memory: Minimum: 4 GB
 Graphics Card: Nvidia GeForce from RTX 2xxx series 4GB RAM
 Monitor: Full-HD to works easy in workstation 23.5 inch

3 UML Class Diagram


In software engineering, a class diagram in the Unified Modeling Language is a sort of static
structure diagram that portrays the structure of a framework by demonstrating the framework's
classes, their attributes, operations, and the connections among objects.

2
4 Class Diagram for calculator assignment

Here we are simply using a single class which is “assignment”. ‘+’ sign shows public and ‘-’ sign
show a private. At first section variables are represented and in second section methods are
represented.

5 Interface Diagram
 A UI flow diagram. User interface-flow diagrams are regularly used for one of two
purposes. Initially, they are used to model the communications that users have with your
software, as characterized in a solitary use case. For instance, a use case can allude to a
few screens and gives understanding into how they are used.
 Following is the interface diagram for the calculator assignment, there is a single
interface in our assignment and total four methods are used.

3
6 Learning Objectives

The development process of the Calculator application will aid the students to:

 Access the Windows Calculator


 Standard Calculator functionality which offers basic operations and evaluates commands
immediately as they are entered.
 Convert between many units of measurement
 Calculation history and memory capability
 Create a simple Java console application
 Understand the object-oriented concepts of inheritance, polymorphism and data hiding
 Create application which request input from users, validate, process the input received
and provide desired output.
 Use features of java like type conversion, interfaces, inheriting interfaces, looping and
branching, packages and I/O classes.

6.1 Understanding the Calculator Application

4
The Calculator application performs both basic and scientific operations. The application
provides user an option to choose between the basic mode and scientific mode. Based on the
option selected by the user, the application calls the corresponding class and the user can perform
various mathematical operations provided in the class. There is a base class in the application
which contains all the methods for calculation, basic as well as scientific. The application
validates the user input also and provides appropriate messages when wrong input is given by the
user.
6.2 Creating the Calculator Application

To create the Calculator application, 5 java files were created. First, an interface iCalc, with the
file name “iCalc.java” is created. Then, we create the base class Calculate, with the file name
“Calculate.java” which contains all the methods for calculation. After the base class, two classes,
Calculator and ScientificCalculator, with the file names as “Calculator.java” and
“ScientificCalculator.java” are created. These classes call the methods defined in the base class
Calculate. Class Calculator contains an instance of Class Calculate, whereas Class
ScientificCalculator inherits Class Calculate and then uses its methods. After creation of all the
above classes, a main class UseCalculate is created, with the file name “UseCalculate.java”
which provides creates instances of Class Calculator or Class ScientificCalculator, based on the
option selected by user.

The Calculate Class (Calculate.java)

Class Calculate contains the business logic of the Calculator application. It contains the methods
for calculation of various mathematical operations like addition, divide and tangent. Class
Calculate uses interfaces by implementing Interface Gui. The class contains following methods:

Method Description
Calculate() Default constructor for the class without any
arguments.
Calculate(Double dblNum, Constructor containing two arguments. This
char cOperator) constructor is used for scientific calculations.
Calculate(int iFirstNum, Constructor containing three arguments. This

5
char cOperator, int constructor is used for basic calculations.
iSecondNum)
doCalculation() Calculates the result based on the numbers and
operator inputted by the user. Overriding the
doCalculation function.of iCalc interface.
getResult() Prints the result of calculation. Overriding the
getResult function.of iCalc interface.
checkSecondNum() In case of division of two numbers, it checks for
value 0 in the second number entered.
checkInt() Checks if basic calculation is performed.
checkDouble() Checks if scientific calculation is performed.

The Calculator Class (Calculator.java)

Class Calculator calculates basic operations, namely, addition, subtraction, multiplication and
division of two numbers. The class provides option to user to enter first number to be calculated,
then the operation to be performed and then, the second number to be used for calculation. The
input is received using java class BufferedReader. Class calculator creates an object of Class
Calculate, by calling its constructor by passing three arguments, First Number, Operator and
Second Number. After the creation of object of Class Calculate, doCalculation() method is called
followed by getResult() method, which presents the result of calculation to the user.

Class Calculator also uses a do-while loop to provide an option to the user perform multiple
calculations, till the user does not indicate the end of processing by typing ‘n’.

6.3 Code for the Calculator Application

Calculator.java
package calculator;
public class Calculator {

/**

6
* @param args the command line arguments
*/
public static void main(String[] args) {
Gui gui = new Gui();
gui.setVisible(true);}
}

7 Implementation
Steps:
• Calculator app is made on NetBeans IDE 8.2. So, first of all we need to open the IDE.
• Create a new project.
• Give name to new application.
• After doing this open the JFrame form.
• Design the User Interface(UI) for the application.
• Event Handling of the
• UI.Design the for the application.

7
8
9
8 Output

10
11

S-ar putea să vă placă și