Asia Pacific Institute of Information Technology: A.N.Ahamed Nishadh (CB004081)
Asia Pacific Institute of Information Technology: A.N.Ahamed Nishadh (CB004081)
TECHNOLOGY
INCOURSE ASSIGNMENT
JAVA PROGRAMMING
Prepared By
[Link] Nishadh (CB004081)
Cohort
DF10A1ICT
Date of Submission
20th September 2011
Instructor
Dr. Dhananjay Kulkarni
Firstly we would like to thank my lecturer Dr. Dhananjay Kulkarnifor all the help
and guidance given while doing this assignment.
Also there are many individuals who have helped me in numerous ways directly
and indirectly so that I was able to complete this assignment.
APIIT Lanka for providing me with resources and the Tech Team at APIIT Lanka
for their assistance at required times.
And last but not least my friends, parents and the well-wishers without whose
moral support and encouragement, I would not have been able to do a good job.
Finally, if there are any shortcomings in this project, then I request to excuse me
for all those and accept this documentation.
Ahamed Nishadh
i
TABLE OF CONTENTS
6.1 – ASSUMPTIONS....................................................................................... 31
6.2 – LIMITATIONS......................................................................................... 31
ii
1.0 - INTRODUCTION
The calculator as we all know is one of the most fascinating devices available. A
device that makes the lives of those who require it easier on a day to day basis
also helps in various other ways when calculations are needed to be done fast and
accurately.
From just being able to add or subtract two numbers to being able to do the most
complex calculations out there, calculators come in many different shapes, sizes
and with various different functionalities to help us out. One point that should be
noted is that the functionality of the calculators keeps improving with the
technology also improving.
As the assignment for our module, I was assigned to design and develop a
calculator program. With the completion of developing the program, I can safely
say that the calculator that I have designed and developed can do all basic
arithmetic problems as well as certain scientific and programmer oriented
calculations. I have used Object Oriented Programming by using the JAVA
Programming language and made my calculator.
In this documentation, I have discussed on how the software works, and displayed
the full source code of the documentation as well as mentioned any and all
assumptions and limitations that the software is made upon or capable of.
1
2.0 – FLOW CHARTS
2.1 – Chart 1
2
2.2 – Chart 2
START
ENTER DIGITS
ENTER
FUNCTION
DO RELEVANT
CALCULATIONS
DISPLAY THE
RESULT
END
3
2.3 – Chart 3
START
ENTER FIRST
DIGIT
ENTER
ENTER
SECOND
FUNCTION
DIGIT
DO RELEVANT
CALCULATIONS
DISPLAY THE
RESULT
END
4
3.0 – CLASS DIAGRAMS
5
4.0 – SOURCE CODE
4.1 – [Link]
package calculator;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class CalculatorView extends FrameView {
public double num[] = new double[10];
public int type[] = new int[10];
public int numbers = 0;
public double total = 0;
public int numberbase = 1;
public int calctype = 0;
public String scimethod;
public double tempval1;
public double tempval2;
public String history[] = new String[50];
public int historycount=0;
public double memory = 0;
public int helpflag;
public String help;
calculate method = new calculate();
public CalculatorView(SingleFrameApplication app) {
private void jrbDecActionPerformed([Link] evt) {
if ([Link]()==true){
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
6
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
}
if(numberbase==1){
//do nothing
}
if(numberbase==2){
int tempnumber;
tempnumber = [Link]([Link](),2);
[Link]([Link](tempnumber));
}
if(numberbase==3){
int tempnumber;
tempnumber = [Link]([Link](),8);
[Link]([Link](tempnumber));
}
7
if(numberbase==4){
int tempnumber;
tempnumber = [Link]([Link](),16);
[Link]([Link](tempnumber));
}
numberbase=1;
}
private void btnNum1ActionPerformed([Link] evt) {
[Link]([Link]()+"1");
}
private void btnNum2ActionPerformed([Link] evt) {
[Link]([Link]()+"2");
}
private void btnNum3ActionPerformed([Link] evt) {
[Link]([Link]()+"3");
}
private void btnNum4ActionPerformed([Link] evt) {
[Link]([Link]()+"4");
}
private void btnNum5ActionPerformed([Link] evt) {
[Link]([Link]()+"5");
}
private void btnNum6ActionPerformed([Link] evt) {
[Link]([Link]()+"6");
}
private void btnNum7ActionPerformed([Link] evt) {
[Link]([Link]()+"7");
}
private void btnNum8ActionPerformed([Link] evt) {
[Link]([Link]()+"8");
}
private void btnNum9ActionPerformed([Link] evt) {
[Link]([Link]()+"9");
}
private void btnNum0ActionPerformed([Link] evt) {
[Link]([Link]()+"0");
}
private void btnPlusActionPerformed([Link] evt) {
if(helpflag==1){
help="The plus operator adds two or more numbers." + "\n" + "\n" +
"Steps: " + "\n" + "1. Enter first number" + "\n" + "2. Click on the '+' button" +
"\n" + "3. Enter second number" + "\n" + "4. Click on the '=' button" + "\n" + "\n"
+ "Example: 2 + 2 = 4" ;
[Link](null,help);
helpflag=0;
}
else{
if (numbers<10){
if (numbers==0){
num[0]=[Link]([Link]());
8
[Link]([Link]()+[Link]()+"+");
[Link]("");
total=num[0];
type[0] =1;
numbers=numbers+1;
}
else{
num[numbers]=[Link]([Link]());
[Link]([Link]()+[Link]()+"+");
[Link]("");
if(type[numbers-1]==1){
total=[Link](total,num[numbers]);
}
if(type[numbers-1]==2){
total=[Link](total,num[numbers]);
}
if(type[numbers-1]==3){
total=[Link](total,num[numbers]);
}
if(type[numbers-1]==4){
total=[Link](total,num[numbers]);
}
type[numbers] =1;
numbers=numbers+1;
}
}
else{
[Link]("You Have Entered More than the Limit Allowed. Pls
Check Again");
}
}
}
private void btnMinActionPerformed([Link] evt) {
if(helpflag==1){
help="The minus operator subtracts two or more numbers." + "\n" + "\n" +
"Steps:" + "\n" + "[Link] first number" + "\n" + "2. Click on the '-' button" + "\n"
+ "3. Enter second number" + "\n" + "4. Click on the '=' button" + "\n" + "\n" +
"Example: 8-2 = 6";
[Link](null,help);
helpflag=0;
}
else{
if (numbers<10){
if (numbers==0){
num[0]=[Link]([Link]());
[Link]([Link]()+[Link]()+"-");
[Link]("");
total=num[0];
type[0] =2;
numbers=numbers+1;
9
}
else{
num[numbers]=[Link]([Link]());
[Link]([Link]()+[Link]()+"-");
[Link]("");
if(type[numbers-1]==1){
total=[Link](total,num[numbers]);
}
if(type[numbers-1]==2){
total=[Link](total,num[numbers]);
}
if(type[numbers-1]==3){
total=[Link](total,num[numbers]);
}
if(type[numbers-1]==4){
total=[Link](total,num[numbers]);
}
type[numbers] =2;
numbers=numbers+1;
}
}
else{
[Link]("You Have Entered More than the Limit Allowed. Pls
Check Again");
}
}
}
private void btnDivActionPerformed([Link] evt) {
if(helpflag==1){
help="Used for dividing two or more numbers." + "\n" + "\n" + "Steps:" +
"\n" + "[Link] first number" + "\n" + "2. Click on the '/' button" + "\n" + "3. Enter
second number" + "\n" + "4. Click on the '=' button" + "\n" + "\n" + "Example:
18/3 = 6";
[Link](null,help);
helpflag=0;
}
else{
if (numbers<10){
if (numbers==0){
num[0]=[Link]([Link]());
[Link]([Link]()+[Link]()+"/");
[Link]("");
total=num[0];
type[0] =4;
numbers=numbers+1;
}
else{
num[numbers]=[Link]([Link]());
[Link]("("+[Link]()+[Link]()+")"+"/");
[Link]("");
10
if(type[numbers-1]==1){
total=[Link](total,num[numbers]);
}
if(type[numbers-1]==2){
total=[Link](total,num[numbers]);
}
if(type[numbers-1]==3){
total=[Link](total,num[numbers]);
}
if(type[numbers-1]==4){
total=[Link](total,num[numbers]);
}
type[numbers] =4;
numbers=numbers+1;
}
}
else{
[Link]("You Have Entered More than the Limit Allowed. Pls
Check Again");
}
}
}
private void btnMulActionPerformed([Link] evt) {
if(helpflag==1){
help="Used for multiplying two or more numbers." + "\n" + "\n" + "Steps:"
+ "\n" + "[Link] first number" + "\n" + "2. Click on the '*' button" + "\n" + "3.
Enter second number" + "\n" + "4. Click on the '=' button" + "\n" + "\n" +
"Example: 6*2 = 12";
[Link](null,help);
helpflag=0;
}
else{
if (numbers<10){
if (numbers==0){
num[0]=[Link]([Link]());
[Link]([Link]()+[Link]()+"*");
[Link]("");
total=num[0];
type[0] =3;
numbers=numbers+1;
}
else{
num[numbers]=[Link]([Link]());
[Link]("("+[Link]()+[Link]()+")"+"*");
[Link]("");
if(type[numbers-1]==1){
total=[Link](total,num[numbers]);
}
if(type[numbers-1]==2){
total=[Link](total,num[numbers]);
11
}
if(type[numbers-1]==3){
total=[Link](total,num[numbers]);
}
if(type[numbers-1]==4){
total=[Link](total,num[numbers]);
}
type[numbers] =3;
numbers=numbers+1;
}
}
else{
[Link]("You Have Entered More than the Limit Allowed. Pls
Check Again");
}
}
}
private void btnEqualActionPerformed([Link] evt) {
if (calctype == 0){
if (numbers<10){
num[numbers]=[Link]([Link]());
[Link]([Link]()+[Link]());
if(type[numbers-1]==1){
total=[Link](total,num[numbers]);
}
if(type[numbers-1]==2){
total=[Link](total,num[numbers]);
}
if(type[numbers-1]==3){
total=[Link](total,num[numbers]);
}
if(type[numbers-1]==4){
total=[Link](total,num[numbers]);
}
[Link]([Link](total));
numbers=numbers+1;
history[historycount]=[Link]()+" = "+[Link]();
historycount=historycount+1;
}
else{
[Link]("You Have Entered More than the Limit Allowed. Pls
Check Again");
}
}
if(calctype == 1){
double temptotal;
if(scimethod=="Power"){
tempval2=[Link]([Link]());
temptotal=[Link](tempval1,tempval2);
[Link]([Link](temptotal));
12
}
if(scimethod=="Percentage"){
tempval2=[Link]([Link]());
temptotal=[Link](tempval1,tempval2);
[Link]([Link](temptotal));
}
if(scimethod=="Mod"){
tempval2=[Link]([Link]());
temptotal=[Link](tempval1,tempval2);
[Link]([Link](temptotal));
}
if(scimethod=="Log"){
tempval1=[Link]([Link]());
temptotal=[Link](tempval1);
[Link]([Link](temptotal));
}
if(scimethod=="Sin"){
tempval1=[Link]([Link]());
temptotal=[Link](tempval1);
[Link]([Link](temptotal));
}
if(scimethod=="Cos"){
tempval1=[Link]([Link]());
temptotal=[Link](tempval1);
[Link]([Link](temptotal));
}
if(scimethod=="Tan"){
tempval1=[Link]([Link]());
temptotal=[Link](tempval1);
[Link]([Link](temptotal));
}
if(scimethod=="ASin"){
tempval1=[Link]([Link]());
temptotal=[Link](tempval1);
[Link]([Link](temptotal));
}
if(scimethod=="ACos"){
tempval1=[Link]([Link]());
temptotal=[Link](tempval1);
[Link]([Link](temptotal));
}
if(scimethod=="ATan"){
tempval1=[Link]([Link]());
temptotal=[Link](tempval1);
[Link]([Link](temptotal));
}
if(scimethod=="Square Root"){
tempval1=[Link]([Link]());
if(tempval1>0){
temptotal=[Link](tempval1);
13
[Link]([Link](temptotal));
}
else{
[Link]("Enter a Positive Value");
}
}
if(scimethod=="EXP"){
tempval1=[Link]([Link]());
if (tempval1>0){
temptotal=[Link](10,tempval1);
[Link]([Link](temptotal));
}
else{
[Link]("Enter a Positive Value");
}
} if(scimethod=="Cube Root"){
tempval1=[Link]([Link]());
temptotal=[Link](tempval1);
[Link]([Link](temptotal));
}
calctype=0;
scimethod="";
[Link]("");
tempval1=0;
tempval2=0;
}
}
private void btnDotActionPerformed([Link] evt) {
[Link]([Link]()+".");
}
private void btnPlusMinActionPerformed([Link] evt) {
if(helpflag==1){
help="The ± operator (unary) converts a positive number to negative and vice
versa." + "\n" + "\n" + "Steps:" + "\n" + "1. Enter a value" + "\n" + "2. Click on
the '±' button" + "\n" + "\n" + "Example: 9 = -9.0";
[Link](null,help);
helpflag=0;
}
else{
[Link]("-"+[Link]());
}
}
private void btnDelActionPerformed([Link] evt) {
if(helpflag==1){
help="The DEL (Clear) button deleted the last entered number.";
[Link](null,help);
helpflag=0;
}
else{
14
[Link]([Link]().substring(0, [Link]().length()-
1));
}
}
private void btnACActionPerformed([Link] evt) {
if(helpflag==1){
help="The AC (All Clear) button, clears everything";
[Link](null,help);
helpflag=1;
}
else{
[Link](num, 0);
[Link](type,0);
[Link](history,"");
numbers = 0;
total = 0;
numberbase=0;
scimethod="";
historycount=0;
tempval1=0;
tempval2=0;
memory=0;
[Link](null);
[Link](null);
}
}
15
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
}
if(numberbase==1){
int tempnumber;
tempnumber = [Link]([Link]());
[Link]([Link](tempnumber));
}
if(numberbase==2){
//do nothing
}
if(numberbase==3){
int tempnumber;
tempnumber = [Link]([Link](),8);
[Link]([Link](tempnumber));
}
if(numberbase==4){
int tempnumber;
tempnumber = [Link]([Link](),16);
[Link]([Link](tempnumber));
}
numberbase=2;
}
private void jrbOctActionPerformed([Link] evt) {
if ([Link]()==true){
16
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](true);
[Link](true);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
}
if(numberbase==1){
int tempnumber;
17
tempnumber = [Link]([Link]());
[Link]([Link](tempnumber));
}
if(numberbase==2){
int tempnumber;
tempnumber = [Link]([Link](),2);
[Link]([Link](tempnumber));
}
if(numberbase==3){
// do nothing
}
if(numberbase==4){
int tempnumber;
tempnumber = [Link]([Link](),16);
[Link]([Link](tempnumber));
}
numberbase=3;
}
private void jrbHexActionPerformed([Link] evt) {
if ([Link]()==true){
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](true);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
18
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
[Link](false);
}
if(numberbase==1){
int tempnumber;
tempnumber = [Link]([Link]());
[Link]([Link](tempnumber).toUpperCase());
}
if(numberbase==2){
int tempnumber;
tempnumber = [Link]([Link](),2);
[Link]([Link](tempnumber).toUpperCase());
}
if(numberbase==3){
int tempnumber;
tempnumber = [Link]([Link](),8);
[Link]([Link](tempnumber).toUpperCase());
}
if(numberbase==4){
//do nothing
}
numberbase=4;
}
private void btnAActionPerformed([Link] evt) {
[Link]([Link]()+"A");
}
private void btnBActionPerformed([Link] evt) {
[Link]([Link]()+"B");
}
private void btnCActionPerformed([Link] evt) {
[Link]([Link]()+"C");
}
private void btnDActionPerformed([Link] evt) {
[Link]([Link]()+"D");
}
19
private void btnEActionPerformed([Link] evt) {
[Link]([Link]()+"E");
}
private void btnFActionPerformed([Link] evt) {
[Link]([Link]()+"F");
}
private void btnPiActionPerformed([Link] evt) {
if(helpflag==1){
help="A mathematical constant whose value is the ratio of any circle's
circumference to its diameter." + "\n" + "p is approximately equal to 3.14159.";
[Link](null,help);
helpflag=1;
}
else{
[Link]([Link]([Link]));
}
}
private void btnSqaureActionPerformed([Link] evt) {
if(helpflag==1){
help="Returns the product of a number with itself." + "\n" + "\n" + "Steps:"
+ "\n" + "1. Enter the value" + "\n" + "2. Click on the 'x²' button" + "\n" + "\n" +
"Example: 5² = 25";
[Link](null,help);
helpflag=0;
}
else{
double temptotal;
temptotal=[Link]([Link]([Link]()),2);
[Link]([Link](temptotal));
}
}
private void btnPowActionPerformed([Link] evt) {
if(helpflag==1){
help="The ^ operator raises a number to a power." + "\n" + "\n" + "Steps:" +
"\n" + "[Link] first number" + "\n" + "2. Click on the '^' button" + "\n" + "3.
Enter second number" + "\n" + "4. Click on the '=' button" + "\n" + "\n" +
"Example: 2^3 = 8" ;
[Link](null,help);
helpflag=0;
}
else{
calctype=1;
scimethod="Power";
[Link](scimethod);
tempval1=[Link]([Link]());
[Link]("");
}
}
private void btnPerActionPerformed([Link] evt) {
if(helpflag==1){
20
help="The % operator finds the percentage of One number." + "\n" + "This is
done by dividing the second value by 100 and multiplying it by the first value" +
"\n" + "\n" + "Steps:" + "\n" + "[Link] first number" + "\n" + "2. Click on the '%'
button" + "\n" + "3. Enter the percentage to be found" + "\n" + "4. Click on the '='
button" + "\n" + "\n" + "Example: 50*(20/100) = 10 " ;
[Link](null,help);
helpflag=0;
}
else{
calctype=1;
scimethod="Percentage";
[Link](scimethod);
tempval1=[Link]([Link]());
[Link]("");
}
}
private void btnModActionPerformed([Link] evt) {
if(helpflag==1){
help="The MOD operator finds the remainder of division of one number by
another." + "\n" + "\n" + "Steps:" + "\n" + "[Link] first number" + "\n" + "2.
Click on the 'MOD' button" + "\n" + "3. Enter second number" + "\n" + "4. Click
on the '=' button" + "\n" + "\n" + "Example: 10 MOD 3 = 1";
[Link](null,help);
helpflag=0;
}
else{
calctype=1;
scimethod="Mod";
[Link](scimethod);
tempval1=[Link]([Link]());
[Link]("");
}
}
private void btnLogActionPerformed([Link] evt) {
if(helpflag==1){
help="Returns the logarithm (base 10) of a double value." + "\n" + "\n" +
"Steps:" + "\n" + "1. Click on the 'LOG' button" + "\n" + "2. Enter a Value" + "\n"
+ "\n" + "Example: LOG 50 = 1.6989";
[Link](null,help);
helpflag=0;
}
else{
calctype=1;
scimethod="Log";
[Link](scimethod);
[Link]("");
}
}
private void btnSinActionPerformed([Link] evt) {
if(helpflag==1){
21
help="Returns the trigonometric sine of an angle." + "\n" + "\n" + "Steps:" +
"\n" + "1. Click on the 'sin' button" + "\n" + "2. Enter a value" + "\n" + "\n" +
"Example: Sin 90 = 1";
[Link](null,help);
helpflag=0;
}
else{
calctype=1;
scimethod="Sin";
[Link](scimethod);
[Link]("");
}
}
private void btnCosActionPerformed([Link] evt) {
if(helpflag==1){
help="Returns the trigonometric cosine of an angle." + "\n" + "\n" + "Steps:" +
"\n" + "1. Click on the 'cos' button" + "\n" + "2. Enter a value" + "\n" + "\n" +
"Example: Cos 60 = 0.5";
[Link](null,help);
helpflag=0;
}
else{
calctype=1;
scimethod="Cos";
[Link](scimethod);
[Link]("");
}
}
private void btnTanActionPerformed([Link] evt) {
if(helpflag==1){
help="Returns the trigonometric tangent of an angle." + "\n" + "\n" +
"Steps:" + "\n" + "1. Click on the 'tan' button" + "\n" + "2. Enter a Value" + "\n" +
"\n" + "Example: Tan 30 = 0.577";
[Link](null,help);
helpflag=0;
}
else{
calctype=1;
scimethod="Tan";
[Link](scimethod);
[Link]("");
}
}
private void btnASinActionPerformed([Link] evt) {
if(helpflag==1){
help="Returns the arc sine of an angle." + "\n" + "\n" + "Steps:" + "\n" + "1.
Click on the 'ASIN' button" + "\n" + "2. Enter A Value" + "\n" + "\n" + "Example:
sin?¹ 1 = 90";
[Link](null,help);
helpflag=0;
22
}
else{
calctype=1;
scimethod="ASin";
[Link](scimethod);
[Link]("");
}
}
private void btnACosActionPerformed([Link] evt) {
if(helpflag==1){
help="Returns the arc cosine of an angle." + "\n" + "\n" + "Steps:" + "\n" +
"1. Click on the 'cos?¹' button" + "\n" + "2. Enter a Value" + "\n" + "\n" +
"Example: cos?¹ 0.25 = 75.5";
[Link](null,help);
helpflag=0;
}
else{
calctype=1;
scimethod="ACos";
[Link](scimethod);
[Link]("");
}
}
23
[Link](scimethod);
[Link]("");
}
}
private void btnMcActionPerformed([Link] evt) {
if(helpflag==1){
help="Clears the memory and sets it to zero.";
[Link](null,help);
helpflag=0;
}
else{
memory=0;
}
}
private void btnMrActionPerformed([Link] evt) {
if(helpflag==1){
help="Displays the value stored in the calculator's memory.";
[Link](null,help);
helpflag=0;
}
else{
[Link]([Link](memory));
}
}
private void btnMsActionPerformed([Link] evt) {
if(helpflag==1){
help="Saves the number on display into the memory for future use.";
[Link](null,help);
helpflag=0;
}
else{
memory=[Link]([Link]());
}
}
private void btnFacActionPerformed([Link] evt) {
if(helpflag==1){
help="Returns the product of all positive integers less than or equal to the
input value." + "\n" + "\n" + "Steps:" + "\n" + "1. Enter the value" + "\n" + "2.
Click on the 'n!' button" + "\n" + "\n" + "Example: 5! = 120";
[Link](null,help);
helpflag=0;
}
else{
int temptotal;
temptotal=[Link]([Link]([Link]()));
[Link]([Link](temptotal));
}
}
private void btnExpActionPerformed([Link] evt) {
if(helpflag==1){
24
help="The EXP operator concatenates zeros to the first input." + "\n" + "The
number of zeros depend on the second input." + "\n" + "\n" + "Steps:" + "\n" +
"[Link] first number" + "\n" + "2. Click on the 'EXP' button" + "\n" + "3. Enter
second number" + "\n" + "4. Click on the '=' button" + "\n" + "\n" + "Example: 1
EXP 3= 1000" ;
[Link](null,help);
helpflag=1;
}
else{
calctype=1;
scimethod="EXP";
[Link](scimethod);
[Link]("");
}
}
25
helpflag=1;
}
else{
calctype=1;
scimethod="Cube Root";
[Link](scimethod);
[Link]("");
}
}
private void btnPowMinActionPerformed([Link] evt) {
double temptotal;
temptotal=[Link]([Link]([Link]()),-1);
[Link]([Link](temptotal));
}
private void btnHelpActionPerformed([Link] evt) {
helpflag = 1;
}
private void btnHistoryActionPerformed([Link] evt) {
String historybutton="";
for (int i=0;i<historycount;i++){
historybutton=historybutton+"\n"+history[i];
}
[Link](null,historybutton);
}
4.2 – [Link]
package calculator;
public class calculate {
public double add(double a, double b){
return a+b;
}
public double subtract(double a, double b){
return a-b;
}
public double multiply(double a, double b){
return a*b;
}
public double division(double a, double b){
return a/b;
}
public double mod(double a, double b){
return a%b;
}
public double power(double a, double b){
return [Link](a, b);
}
public double percent(double a, double b){
26
return (a*(b/100));
}
public double log(double a){
return Math.log10(a);
}
public double sin(double a){
return [Link]([Link](a));
}
public double cos(double a){
return [Link]([Link](a));
}
public double tan(double a){
return [Link]([Link](a));
}
public double asin(double a){
return [Link]([Link](a));
}
public double acos(double a){
return [Link]([Link](a));
}
public double atan(double a){
return [Link]([Link](a));
}
public double sqrt(double a){
return [Link](a);
}
public int factorial(int a){
int i;
int fact=1;
for(i=1;i<=a;i++){
fact=fact*i;
}
return fact;
}
public double fractions(double a){
return 1/a;
}
public double cbrt(double a){
return [Link](a);
}
}
27
5.0 – TEST PLAN
EXP Button
Click on ‘EXP’
should be
7. EXP Enter number EXP 3 1000.0
clicked before
Click on ‘=’
entering number
28
be entered before Click on ‘%’
clicking ‘%’ Enter second
number
Click on ‘=’
Enter a binary or
Octal or a
hexadecimal
9. Decimal - value 1010 10
Click on
‘Decimal’ to
convert
Enter a binary or
Octal or a
hexadecimal
Hexadecima
10. - value 1010 A
l
Click on
‘Hexadecimal’ to
convert
Enter a binary or
Octal or a
hexadecimal
11. Binary - value C 1100
Click on
‘Binary’ to
convert
Click on ‘AC’ to
12. All Clear - clear the text 1234 -
field
Click on ‘DEL’
13. DEL - to clear one by 1234 123
one
Click on
2.0+2.0=4
14. History - ‘History’ to view -
Sin 90.0=1.0
calculation log
A number should
Enter a value
15. Unary be entered before 9 -9.0
Click on ‘±’
clicking ‘±’
‘SIN’ should be
Click on ‘SIN’
clicked before
16. Sin Enter a value sin 90 1.0
entering a
Click on ‘=’
number
‘COS’ should be
Click on ‘COS’
clicked before
17. Cos Enter a value cos 60 0.5
entering a
Click on ‘=’
number
‘TAN’ should be
Click on ‘TAN’
clicked before
18. Tan Enter a value tan 30 0.577
entering a
Click on ‘=’
number
19. ASin ‘ASIN’ should Click on ‘ASIN’ ASin 1 90.0
29
be clicked before Enter a value
entering a Click on ‘=’
number
‘ACOS’ should
Click on ‘ACOS’
be clicked before ACos
20. ACos Enter a value 75.5
entering a 0.25
Click on ‘=’
number
‘ATAN’ should Click on
be clicked before ‘ATAN’ ATan
21. ATan 36.86
entering a Enter a value 0.75
number Click on ‘=’
A number should Enter a value
22. Square be entered before Click on ‘x²’ 5² 25.0
clicking ‘x²’ Click on ‘=’
A number should Enter a value
23. Cube be entered before Click on ‘x³’ 4³ 64.0
clicking ‘x³’ Click on ‘=’
‘√’ should be
Click on ‘√’
clicked before
24. Square Root Enter a value √16 4.0
entering a
Click on ‘=’
number
‘∛’ should be
Click on ‘∛’
clicked before
25. Cube Root Enter a value ∛8 2.0
entering a
Click on ‘=’
number
28. π - Click on ‘π’ - 3.14159…..
A number should
Enter a value
29. 1/x be entered before 1/2 0.5
Click on ‘1/x’
clicking ‘1/x’
A number should
Enter a value
30. n! be entered before 5! 120.0
Click on ‘n!’
clicking ‘n!’
‘LOG’ should be
Click on ‘LOG’
clicked before
31. log Enter a value LOG 50 1.6989
entering a
Click on ‘=’
number
A number should
Memory be present in the
32. Click on ‘MS’ - -
Save text field, in
order to be saved
Memory
33. - Click on ‘MR’ - 4.0
Recall
Memory
34. - Click on ‘MC’ - -
Clear
30
6.0 – ASSUMPTIONS AND LIMITATIONS
Although I have done this calculator to the best of my abilities, there are certain
assumptions that I have taken while doing programming this calculator and also
some limitations that the calculator is bound to. They are listed below.
6.1 – ASSUMPTIONS
1. The user will always enter a value before entering a sign. If not, 0 is taken
into account automatically and calculations are performed.
2. Input is given by way of clicking the buttons on screen by the mouse
pointer only and not by entering values through the keyboard.
6.2 – LIMITATIONS
31
7.0 – BIBLIOGRAPHY
[Link], 2011. Java 2 Platform Standard Ed. 7.0. [Online] Available at:
[Link] [Accessed
2011].
32