SlideShare a Scribd company logo
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

202: When the user clicks a JCheckBox, a(n) occurs.
202: When the user clicks a JCheckBox, a(n) occurs.202: When the user clicks a JCheckBox, a(n) occurs.
202: When the user clicks a JCheckBox, a(n) occurs.sukeshsuresh189
 
3: A(n) ________ enables a program to read data from the user.
3: A(n) ________ enables a program to read data from the user.3: A(n) ________ enables a program to read data from the user.
3: A(n) ________ enables a program to read data from the user.sukeshsuresh189
 
22: The logical relationship between radio buttons is maintained by objects o...
22: The logical relationship between radio buttons is maintained by objects o...22: The logical relationship between radio buttons is maintained by objects o...
22: The logical relationship between radio buttons is maintained by objects o...sukeshsuresh189
 
19: When the user presses Enter in a JTextField, the GUI component generates ...
19: When the user presses Enter in a JTextField, the GUI component generates ...19: When the user presses Enter in a JTextField, the GUI component generates ...
19: When the user presses Enter in a JTextField, the GUI component generates ...sukeshsuresh189
 
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 Stringsukeshsuresh189
 
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 havesukeshsuresh189
 
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
 
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
 
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
 
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
 
Mmc manual
Mmc manualMmc manual
Mmc manual
Urvi Surat
 

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

202: When the user clicks a JCheckBox, a(n) occurs.
202: When the user clicks a JCheckBox, a(n) occurs.202: When the user clicks a JCheckBox, a(n) occurs.
202: When the user clicks a JCheckBox, a(n) occurs.
 
3: A(n) ________ enables a program to read data from the user.
3: A(n) ________ enables a program to read data from the user.3: A(n) ________ enables a program to read data from the user.
3: A(n) ________ enables a program to read data from the user.
 
22: The logical relationship between radio buttons is maintained by objects o...
22: The logical relationship between radio buttons is maintained by objects o...22: The logical relationship between radio buttons is maintained by objects o...
22: The logical relationship between radio buttons is maintained by objects o...
 
19: When the user presses Enter in a JTextField, the GUI component generates ...
19: When the user presses Enter in a JTextField, the GUI component generates ...19: When the user presses Enter in a JTextField, the GUI component generates ...
19: When the user presses Enter in a JTextField, the GUI component generates ...
 
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?
 
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?
 
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...
 
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

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
hainesburchett26321
 
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
hainesburchett26321
 
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
hainesburchett26321
 
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
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
 
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
hainesburchett26321
 
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
hainesburchett26321
 
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
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
 
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
hainesburchett26321
 
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
hainesburchett26321
 
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
hainesburchett26321
 
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
hainesburchett26321
 
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
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

Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 

Recently uploaded (20)

Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 

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