SlideShare a Scribd company logo
1 of 4
Download to read offline
Question: Hello, I need some assistance in writing a java pr...
Hello, I need some assistance in writing a java program using stacks (LIFO).
Create a Calculator w/ GUI
Write a program that graphically displays a working calculator for simple infix expressions that
consist of: single-digit operands, the operators: +, -, *, and /, and parentheses.
Make the following assumptions:
unary operators (e.g. -2) are illegal
all operations, including division, are integer operations (and results are integers)
the input expression contains no embedded spaces and no illegal characters
the input expression is a syntactically correct infix expression
division by zero will not occur (consider how you can remove this restriction)
Create a GUI application, the calculator has a display and a keypad of 20 keys, which are
arranged as follows:
C
<
Q
/
7
8
9
*
4
5
6
-
1
2
3
+
0
(
)
=
As the user presses keys to enter an infix expression, the corresponding characters appear in the
display. The C (Clear) key erases all input entered so far; the < (Backspace) key erases the last
character entered. When the user presses the = key, the expression is evaluated and the result
appended to the right end of the expression in the display window. The user can then press C and
enter another expression. If the user presses the Q (Quit) key, the calculator ceases operation and
is erased from the screen.
C
<
Q
/
7
8
9
*
4
5
6
-
1
2
3
+
0
(
)
=
Solution
import java.awt.*;
import java.awt.event.*;
public class MyCalculator extends Frame
{
public boolean setClear=true;
double number, memValue;
char op;
String digitButtonText[] = {"7", "8", "9", "4", "5", "6", "1", "2", "3", "0", "+/-",
"." };
String operatorButtonText[] = {"/", "sqrt", "*", "%", "-", "1/X", "+", "=" };
String memoryButtonText[] = {"MC", "MR", "MS", "M+" };
String specialButtonText[] = {"Backspc", "C", "CE" };
String buttonsText[]={"C","<","Q","/"};
String buttonText1[]={"7","8","9","*"};
String ButtonsText2[]={"4","5","6","-"};
String ButtonText3[]={"1","2","3","+"};
String ButtonText4[]={"0","(",")","="};
MyDigitButton digitButton[]=new MyDigitButton[digitButtonText.length];
MyOperatorButton operatorButton[]=new MyOperatorButton[operatorButtonText.length];
MyMemoryButton memoryButton[]=new MyMemoryButton[memoryButtonText.length];
MySpecialButton specialButton[]=new MySpecialButton[specialButtonText.length];
Label displayLabel=new Label("0",Label.RIGHT);
Label memLabel=new Label(" ",Label.RIGHT);
final int FRAME_WIDTH=325,FRAME_HEIGHT=325;
final int HEIGHT=30, WIDTH=30, H_SPACE=10,V_SPACE=10;
final int TOPX=30, TOPY=50;
///////////////////////////
MyCalculator(String frameText)//constructor
{
super(frameText);
int tempX=TOPX, y=TOPY;
displayLabel.setBounds(tempX,y,240,HEIGHT);
displayLabel.setBackground(Color.BLUE);
displayLabel.setForeground(Color.WHITE);
add(displayLabel);
memLabel.setBounds(TOPX, TOPY+HEIGHT+ V_SPACE,WIDTH, HEIGHT);
add(memLabel);
// set Co-ordinates for Memory Buttons
tempX=TOPX;
y=TOPY+2*(HEIGHT+V_SPACE);
for(int i=0; i0)
resText=resText.substring(0,resText.length()-2);
return resText;
}
////////////////////////////////////////
public static void main(String []args)
{
new MyCalculator("Calculator -Ravi");
}
}
/*******************************************/
class MyDigitButton extends Button implements ActionListener
{
MyCalculator cl;
//////////////////////////////////////////
MyDigitButton(int x,int y, int width,int height,String cap, MyCalculator clc)
{
super(cap);
setBounds(x,y,width,height);
this.cl=clc;
this.cl.add(this);
addActionListener(this);
}
////////////////////////////////////////////////
static boolean isInString(String s, char ch)
{
for(int i=0; i

More Related Content

Similar to Question Hello, I need some assistance in writing a java pr...Hel.pdf

12: When an object is concatenated with a String
12: When an object is concatenated with a String12: When an object is concatenated with a String
12: When an object is concatenated with a String
sukeshsuresh189
 
5: Every Java application is required to have
5: Every Java application is required to have5: Every Java application is required to have
5: Every Java application is required to have
sukeshsuresh189
 
15: Which method call converts the value in variable stringVariable to an int...
15: Which method call converts the value in variable stringVariable to an int...15: Which method call converts the value in variable stringVariable to an int...
15: Which method call converts the value in variable stringVariable to an int...
sukeshsuresh189
 
16: Which of the following is the method used to display a dialog box to gath...
16: Which of the following is the method used to display a dialog box to gath...16: Which of the following is the method used to display a dialog box to gath...
16: Which of the following is the method used to display a dialog box to gath...
sukeshsuresh189
 
13: What do the following statements do?
13: What do the following statements do?13: What do the following statements do?
13: What do the following statements do?
sukeshsuresh189
 
Comp 328 final guide (devry)
Comp 328 final guide (devry)Comp 328 final guide (devry)
Comp 328 final guide (devry)
sukeshsuresh189
 
7: Assume the following class declaration.
7: Assume the following class declaration.7: Assume the following class declaration.
7: Assume the following class declaration.
sukeshsuresh189
 
8: Which statement below could be used to randomly select a state from an arr...
8: Which statement below could be used to randomly select a state from an arr...8: Which statement below could be used to randomly select a state from an arr...
8: Which statement below could be used to randomly select a state from an arr...
sukeshsuresh189
 
11: Which is a correct way to invoke the static method sqrt of the Math class?
11: Which is a correct way to invoke the static method sqrt of the Math class?11: Which is a correct way to invoke the static method sqrt of the Math class?
11: Which is a correct way to invoke the static method sqrt of the Math class?
sukeshsuresh189
 
14: Consider the class below:
14: Consider the class below:14: Consider the class below:
14: Consider the class below:
sukeshsuresh189
 
18: Which of the following does not generate an event?
18: Which of the following does not generate an event?18: Which of the following does not generate an event?
18: Which of the following does not generate an event?
sukeshsuresh189
 
17: provides the basic attributes and behaviors of a window—a title bar at th...
17: provides the basic attributes and behaviors of a window—a title bar at th...17: provides the basic attributes and behaviors of a window—a title bar at th...
17: provides the basic attributes and behaviors of a window—a title bar at th...
sukeshsuresh189
 
23: Which layout manager is the default for JPanel?
23: Which layout manager is the default for JPanel?23: Which layout manager is the default for JPanel?
23: Which layout manager is the default for JPanel?
sukeshsuresh189
 
1: The .class extension on a file means that the file
1:  The .class extension on a file means that the file1:  The .class extension on a file means that the file
1: The .class extension on a file means that the file
sukeshsuresh189
 
4: Which of the following is a Scanner method?
4: Which of the following is a Scanner method?4: Which of the following is a Scanner method?
4: Which of the following is a Scanner method?
sukeshsuresh189
 
Comp 328 final guide (devry)
Comp 328 final guide (devry)Comp 328 final guide (devry)
Comp 328 final guide (devry)
sukeshsuresh189
 
10: In the Java graphics system, coordinate units are measured in ________.
10: In the Java graphics system, coordinate units are measured in ________.10: In the Java graphics system, coordinate units are measured in ________.
10: In the Java graphics system, coordinate units are measured in ________.
sukeshsuresh189
 
Hello, I need some assistance in writing a java program THAT MUST US.pdf
Hello, I need some assistance in writing a java program THAT MUST US.pdfHello, I need some assistance in writing a java program THAT MUST US.pdf
Hello, I need some assistance in writing a java program THAT MUST US.pdf
FashionColZone
 

Similar to Question Hello, I need some assistance in writing a java pr...Hel.pdf (20)

12: When an object is concatenated with a String
12: When an object is concatenated with a String12: When an object is concatenated with a String
12: When an object is concatenated with a String
 
5: Every Java application is required to have
5: Every Java application is required to have5: Every Java application is required to have
5: Every Java application is required to have
 
15: Which method call converts the value in variable stringVariable to an int...
15: Which method call converts the value in variable stringVariable to an int...15: Which method call converts the value in variable stringVariable to an int...
15: Which method call converts the value in variable stringVariable to an int...
 
16: Which of the following is the method used to display a dialog box to gath...
16: Which of the following is the method used to display a dialog box to gath...16: Which of the following is the method used to display a dialog box to gath...
16: Which of the following is the method used to display a dialog box to gath...
 
13: What do the following statements do?
13: What do the following statements do?13: What do the following statements do?
13: What do the following statements do?
 
Comp 328 final guide (devry)
Comp 328 final guide (devry)Comp 328 final guide (devry)
Comp 328 final guide (devry)
 
7: Assume the following class declaration.
7: Assume the following class declaration.7: Assume the following class declaration.
7: Assume the following class declaration.
 
8: Which statement below could be used to randomly select a state from an arr...
8: Which statement below could be used to randomly select a state from an arr...8: Which statement below could be used to randomly select a state from an arr...
8: Which statement below could be used to randomly select a state from an arr...
 
11: Which is a correct way to invoke the static method sqrt of the Math class?
11: Which is a correct way to invoke the static method sqrt of the Math class?11: Which is a correct way to invoke the static method sqrt of the Math class?
11: Which is a correct way to invoke the static method sqrt of the Math class?
 
14: Consider the class below:
14: Consider the class below:14: Consider the class below:
14: Consider the class below:
 
18: Which of the following does not generate an event?
18: Which of the following does not generate an event?18: Which of the following does not generate an event?
18: Which of the following does not generate an event?
 
17: provides the basic attributes and behaviors of a window—a title bar at th...
17: provides the basic attributes and behaviors of a window—a title bar at th...17: provides the basic attributes and behaviors of a window—a title bar at th...
17: provides the basic attributes and behaviors of a window—a title bar at th...
 
23: Which layout manager is the default for JPanel?
23: Which layout manager is the default for JPanel?23: Which layout manager is the default for JPanel?
23: Which layout manager is the default for JPanel?
 
1: The .class extension on a file means that the file
1:  The .class extension on a file means that the file1:  The .class extension on a file means that the file
1: The .class extension on a file means that the file
 
4: Which of the following is a Scanner method?
4: Which of the following is a Scanner method?4: Which of the following is a Scanner method?
4: Which of the following is a Scanner method?
 
Comp 328 final guide (devry)
Comp 328 final guide (devry)Comp 328 final guide (devry)
Comp 328 final guide (devry)
 
10: In the Java graphics system, coordinate units are measured in ________.
10: In the Java graphics system, coordinate units are measured in ________.10: In the Java graphics system, coordinate units are measured in ________.
10: In the Java graphics system, coordinate units are measured in ________.
 
17 Jo P May 08
17 Jo P May 0817 Jo P May 08
17 Jo P May 08
 
Hello, I need some assistance in writing a java program THAT MUST US.pdf
Hello, I need some assistance in writing a java program THAT MUST US.pdfHello, I need some assistance in writing a java program THAT MUST US.pdf
Hello, I need some assistance in writing a java program THAT MUST US.pdf
 
Mmc manual
Mmc manualMmc manual
Mmc manual
 

More from hainesburchett26321

Understanding Risk Terms and DefinitionsSolutionWhat is Risk.pdf
Understanding Risk Terms and DefinitionsSolutionWhat is Risk.pdfUnderstanding Risk Terms and DefinitionsSolutionWhat is Risk.pdf
Understanding Risk Terms and DefinitionsSolutionWhat is Risk.pdf
hainesburchett26321
 
Thomas Townsend has an embarrassing criminal past. In 1985, he was c.pdf
Thomas Townsend has an embarrassing criminal past. In 1985, he was c.pdfThomas Townsend has an embarrassing criminal past. In 1985, he was c.pdf
Thomas Townsend has an embarrassing criminal past. In 1985, he was c.pdf
hainesburchett26321
 
The lymphatic system is composed of all of the following except lymph.pdf
The lymphatic system is composed of all of the following except lymph.pdfThe lymphatic system is composed of all of the following except lymph.pdf
The lymphatic system is composed of all of the following except lymph.pdf
hainesburchett26321
 
Surgeons have sometimes cut the corpus callosum as a treatment for w.pdf
Surgeons have sometimes cut the corpus callosum as a treatment for w.pdfSurgeons have sometimes cut the corpus callosum as a treatment for w.pdf
Surgeons have sometimes cut the corpus callosum as a treatment for w.pdf
hainesburchett26321
 
Please help I think the answer is B, but Im not too sure.A. Amni.pdf
Please help I think the answer is B, but Im not too sure.A. Amni.pdfPlease help I think the answer is B, but Im not too sure.A. Amni.pdf
Please help I think the answer is B, but Im not too sure.A. Amni.pdf
hainesburchett26321
 
Need help writing the code for a basic java tic tac toe game Tic.pdf
Need help writing the code for a basic java tic tac toe game Tic.pdfNeed help writing the code for a basic java tic tac toe game Tic.pdf
Need help writing the code for a basic java tic tac toe game Tic.pdf
hainesburchett26321
 
following concepts from Johnsons book in Ch. 1, Ch. 2 or Ch. 3-- w.pdf
following concepts from Johnsons book in Ch. 1, Ch. 2 or Ch. 3-- w.pdffollowing concepts from Johnsons book in Ch. 1, Ch. 2 or Ch. 3-- w.pdf
following concepts from Johnsons book in Ch. 1, Ch. 2 or Ch. 3-- w.pdf
hainesburchett26321
 
Explain how the structure and function are linked together for the f.pdf
Explain how the structure and function are linked together for the f.pdfExplain how the structure and function are linked together for the f.pdf
Explain how the structure and function are linked together for the f.pdf
hainesburchett26321
 

More from hainesburchett26321 (20)

Write an identity in terms of sines and cosines to simplify it. The .pdf
Write an identity in terms of sines and cosines to simplify it.  The .pdfWrite an identity in terms of sines and cosines to simplify it.  The .pdf
Write an identity in terms of sines and cosines to simplify it. The .pdf
 
What is a sampling distribution Describe the similarities between t.pdf
What is a sampling distribution Describe the similarities between t.pdfWhat is a sampling distribution Describe the similarities between t.pdf
What is a sampling distribution Describe the similarities between t.pdf
 
What is the easiest to memorize the order of all the Eras and their .pdf
What is the easiest to memorize the order of all the Eras and their .pdfWhat is the easiest to memorize the order of all the Eras and their .pdf
What is the easiest to memorize the order of all the Eras and their .pdf
 
What is stock split How is it equivalent to paying a dividendS.pdf
What is stock split How is it equivalent to paying a dividendS.pdfWhat is stock split How is it equivalent to paying a dividendS.pdf
What is stock split How is it equivalent to paying a dividendS.pdf
 
Understanding Risk Terms and DefinitionsSolutionWhat is Risk.pdf
Understanding Risk Terms and DefinitionsSolutionWhat is Risk.pdfUnderstanding Risk Terms and DefinitionsSolutionWhat is Risk.pdf
Understanding Risk Terms and DefinitionsSolutionWhat is Risk.pdf
 
Thomas Townsend has an embarrassing criminal past. In 1985, he was c.pdf
Thomas Townsend has an embarrassing criminal past. In 1985, he was c.pdfThomas Townsend has an embarrassing criminal past. In 1985, he was c.pdf
Thomas Townsend has an embarrassing criminal past. In 1985, he was c.pdf
 
The lymphatic system is composed of all of the following except lymph.pdf
The lymphatic system is composed of all of the following except lymph.pdfThe lymphatic system is composed of all of the following except lymph.pdf
The lymphatic system is composed of all of the following except lymph.pdf
 
Surgeons have sometimes cut the corpus callosum as a treatment for w.pdf
Surgeons have sometimes cut the corpus callosum as a treatment for w.pdfSurgeons have sometimes cut the corpus callosum as a treatment for w.pdf
Surgeons have sometimes cut the corpus callosum as a treatment for w.pdf
 
5 of 12 Incorrect Sapling Learning assify these items according to wh.pdf
5 of 12 Incorrect Sapling Learning assify these items according to wh.pdf5 of 12 Incorrect Sapling Learning assify these items according to wh.pdf
5 of 12 Incorrect Sapling Learning assify these items according to wh.pdf
 
Recall that E. coli can grow in glucose-salts medium, which contains .pdf
Recall that E. coli can grow in glucose-salts medium, which contains .pdfRecall that E. coli can grow in glucose-salts medium, which contains .pdf
Recall that E. coli can grow in glucose-salts medium, which contains .pdf
 
Random samples of 200 men, all retired were classified according to .pdf
Random samples of 200 men, all retired were classified according to .pdfRandom samples of 200 men, all retired were classified according to .pdf
Random samples of 200 men, all retired were classified according to .pdf
 
Please help I think the answer is B, but Im not too sure.A. Amni.pdf
Please help I think the answer is B, but Im not too sure.A. Amni.pdfPlease help I think the answer is B, but Im not too sure.A. Amni.pdf
Please help I think the answer is B, but Im not too sure.A. Amni.pdf
 
Need help writing the code for a basic java tic tac toe game Tic.pdf
Need help writing the code for a basic java tic tac toe game Tic.pdfNeed help writing the code for a basic java tic tac toe game Tic.pdf
Need help writing the code for a basic java tic tac toe game Tic.pdf
 
Inventory is recorded at what value on the balance Sheet Inven.pdf
Inventory is recorded at what value on the balance Sheet Inven.pdfInventory is recorded at what value on the balance Sheet Inven.pdf
Inventory is recorded at what value on the balance Sheet Inven.pdf
 
If you are monitoring a 1 V source on an oscilloscope and the scope m.pdf
If you are monitoring a 1 V source on an oscilloscope and the scope m.pdfIf you are monitoring a 1 V source on an oscilloscope and the scope m.pdf
If you are monitoring a 1 V source on an oscilloscope and the scope m.pdf
 
If Emery has $1,700 to invest at 7 per year compounded monthly, how .pdf
If Emery has $1,700 to invest at 7 per year compounded monthly, how .pdfIf Emery has $1,700 to invest at 7 per year compounded monthly, how .pdf
If Emery has $1,700 to invest at 7 per year compounded monthly, how .pdf
 
Identify and discuss features of organizations managers need to know.pdf
Identify and discuss features of organizations managers need to know.pdfIdentify and discuss features of organizations managers need to know.pdf
Identify and discuss features of organizations managers need to know.pdf
 
he first photosynthetic organisms to oxygenate the Earth’s atmospher.pdf
he first photosynthetic organisms to oxygenate the Earth’s atmospher.pdfhe first photosynthetic organisms to oxygenate the Earth’s atmospher.pdf
he first photosynthetic organisms to oxygenate the Earth’s atmospher.pdf
 
following concepts from Johnsons book in Ch. 1, Ch. 2 or Ch. 3-- w.pdf
following concepts from Johnsons book in Ch. 1, Ch. 2 or Ch. 3-- w.pdffollowing concepts from Johnsons book in Ch. 1, Ch. 2 or Ch. 3-- w.pdf
following concepts from Johnsons book in Ch. 1, Ch. 2 or Ch. 3-- w.pdf
 
Explain how the structure and function are linked together for the f.pdf
Explain how the structure and function are linked together for the f.pdfExplain how the structure and function are linked together for the f.pdf
Explain how the structure and function are linked together for the f.pdf
 

Recently uploaded

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answers
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health Education
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 

Question Hello, I need some assistance in writing a java pr...Hel.pdf

  • 1. Question: Hello, I need some assistance in writing a java pr... Hello, I need some assistance in writing a java program using stacks (LIFO). Create a Calculator w/ GUI Write a program that graphically displays a working calculator for simple infix expressions that consist of: single-digit operands, the operators: +, -, *, and /, and parentheses. Make the following assumptions: unary operators (e.g. -2) are illegal all operations, including division, are integer operations (and results are integers) the input expression contains no embedded spaces and no illegal characters the input expression is a syntactically correct infix expression division by zero will not occur (consider how you can remove this restriction) Create a GUI application, the calculator has a display and a keypad of 20 keys, which are arranged as follows: C < Q / 7 8 9 * 4 5 6 - 1 2 3 + 0 ( ) = As the user presses keys to enter an infix expression, the corresponding characters appear in the display. The C (Clear) key erases all input entered so far; the < (Backspace) key erases the last
  • 2. character entered. When the user presses the = key, the expression is evaluated and the result appended to the right end of the expression in the display window. The user can then press C and enter another expression. If the user presses the Q (Quit) key, the calculator ceases operation and is erased from the screen. C < Q / 7 8 9 * 4 5 6 - 1 2 3 + 0 ( ) = Solution import java.awt.*; import java.awt.event.*; public class MyCalculator extends Frame { public boolean setClear=true; double number, memValue; char op;
  • 3. String digitButtonText[] = {"7", "8", "9", "4", "5", "6", "1", "2", "3", "0", "+/-", "." }; String operatorButtonText[] = {"/", "sqrt", "*", "%", "-", "1/X", "+", "=" }; String memoryButtonText[] = {"MC", "MR", "MS", "M+" }; String specialButtonText[] = {"Backspc", "C", "CE" }; String buttonsText[]={"C","<","Q","/"}; String buttonText1[]={"7","8","9","*"}; String ButtonsText2[]={"4","5","6","-"}; String ButtonText3[]={"1","2","3","+"}; String ButtonText4[]={"0","(",")","="}; MyDigitButton digitButton[]=new MyDigitButton[digitButtonText.length]; MyOperatorButton operatorButton[]=new MyOperatorButton[operatorButtonText.length]; MyMemoryButton memoryButton[]=new MyMemoryButton[memoryButtonText.length]; MySpecialButton specialButton[]=new MySpecialButton[specialButtonText.length]; Label displayLabel=new Label("0",Label.RIGHT); Label memLabel=new Label(" ",Label.RIGHT); final int FRAME_WIDTH=325,FRAME_HEIGHT=325; final int HEIGHT=30, WIDTH=30, H_SPACE=10,V_SPACE=10; final int TOPX=30, TOPY=50; /////////////////////////// MyCalculator(String frameText)//constructor { super(frameText); int tempX=TOPX, y=TOPY; displayLabel.setBounds(tempX,y,240,HEIGHT); displayLabel.setBackground(Color.BLUE); displayLabel.setForeground(Color.WHITE); add(displayLabel); memLabel.setBounds(TOPX, TOPY+HEIGHT+ V_SPACE,WIDTH, HEIGHT); add(memLabel); // set Co-ordinates for Memory Buttons tempX=TOPX; y=TOPY+2*(HEIGHT+V_SPACE); for(int i=0; i0) resText=resText.substring(0,resText.length()-2); return resText;
  • 4. } //////////////////////////////////////// public static void main(String []args) { new MyCalculator("Calculator -Ravi"); } } /*******************************************/ class MyDigitButton extends Button implements ActionListener { MyCalculator cl; ////////////////////////////////////////// MyDigitButton(int x,int y, int width,int height,String cap, MyCalculator clc) { super(cap); setBounds(x,y,width,height); this.cl=clc; this.cl.add(this); addActionListener(this); } //////////////////////////////////////////////// static boolean isInString(String s, char ch) { for(int i=0; i