SlideShare a Scribd company logo
Hello, I need some assistance in writing a java program THAT MUST USE 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 javax.swing.*;
import java.awt.event.*;
public class Calculator extends JFrame implements ActionListener {
JPanel[] row = new JPanel[5];
JButton[] button = new JButton[19];
String[] buttonString = {"7", "8", "9", "+",
"4", "5", "6", "-",
"1", "2", "3", "*",
".", "/", "C", "",
"+/-", "=", "0"};
int[] dimW = {300,45,100,90};
int[] dimH = {35, 40};
Dimension displayDimension = new Dimension(dimW[0], dimH[0]);
Dimension regularDimension = new Dimension(dimW[1], dimH[1]);
Dimension rColumnDimension = new Dimension(dimW[2], dimH[1]);
Dimension zeroButDimension = new Dimension(dimW[3], dimH[1]);
boolean[] function = new boolean[4];
double[] temporary = {0, 0};
JTextArea display = new JTextArea(1,20);
Font font = new Font("Times new Roman", Font.BOLD, 14);
Calculator() {
super("Calculator");
setDesign();
setSize(380, 250);
setResizable(false);
setDefaultCloseOperation(EXIT_ON_CLOSE);
GridLayout grid = new GridLayout(5,5);
setLayout(grid);
for(int i = 0; i < 4; i++)
function[i] = false;
FlowLayout f1 = new FlowLayout(FlowLayout.CENTER);
FlowLayout f2 = new FlowLayout(FlowLayout.CENTER,1,1);
for(int i = 0; i < 5; i++)
row[i] = new JPanel();
row[0].setLayout(f1);
for(int i = 1; i < 5; i++)
row[i].setLayout(f2);
for(int i = 0; i < 19; i++) {
button[i] = new JButton();
button[i].setText(buttonString[i]);
button[i].setFont(font);
button[i].addActionListener(this);
}
display.setFont(font);
display.setEditable(false);
display.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
display.setPreferredSize(displayDimension);
for(int i = 0; i < 14; i++)
button[i].setPreferredSize(regularDimension);
for(int i = 14; i < 18; i++)
button[i].setPreferredSize(rColumnDimension);
button[18].setPreferredSize(zeroButDimension);
row[0].add(display);
add(row[0]);
for(int i = 0; i < 4; i++)
row[1].add(button[i]);
row[1].add(button[14]);
add(row[1]);
for(int i = 4; i < 8; i++)
row[2].add(button[i]);
row[2].add(button[15]);
add(row[2]);
for(int i = 8; i < 12; i++)
row[3].add(button[i]);
row[3].add(button[16]);
add(row[3]);
row[4].add(button[18]);
for(int i = 12; i < 14; i++)
row[4].add(button[i]);
row[4].add(button[17]);
add(row[4]);
setVisible(true);
}
public void clear() {
try {
display.setText("");
for(int i = 0; i < 4; i++)
function[i] = false;
for(int i = 0; i < 2; i++)
temporary[i] = 0;
} catch(NullPointerException e) {
}
}
public void getSqrt() {
try {
double value = Math.sqrt(Double.parseDouble(display.getText()));
display.setText(Double.toString(value));
} catch(NumberFormatException e) {
}
}
public void getPosNeg() {
try {
double value = Double.parseDouble(display.getText());
if(value != 0) {
value = value * (-1);
display.setText(Double.toString(value));
}
else {
}
} catch(NumberFormatException e) {
}
}
public void getResult() {
double result = 0;
temporary[1] = Double.parseDouble(display.getText());
String temp0 = Double.toString(temporary[0]);
String temp1 = Double.toString(temporary[1]);
try {
if(temp0.contains("-")) {
String[] temp00 = temp0.split("-", 2);
temporary[0] = (Double.parseDouble(temp00[1]) * -1);
}
if(temp1.contains("-")) {
String[] temp11 = temp1.split("-", 2);
temporary[1] = (Double.parseDouble(temp11[1]) * -1);
}
} catch(ArrayIndexOutOfBoundsException e) {
}
try {
if(function[2] == true)
result = temporary[0] * temporary[1];
else if(function[3] == true)
result = temporary[0] / temporary[1];
else if(function[0] == true)
result = temporary[0] + temporary[1];
else if(function[1] == true)
result = temporary[0] - temporary[1];
display.setText(Double.toString(result));
for(int i = 0; i < 4; i++)
function[i] = false;
} catch(NumberFormatException e) {
}
}
public final void setDesign() {
try {
UIManager.setLookAndFeel(
"com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
} catch(Exception e) {
}
}
@Override
public void actionPerformed(ActionEvent ae) {
if(ae.getSource() == button[0])
display.append("7");
if(ae.getSource() == button[1])
display.append("8");
if(ae.getSource() == button[2])
display.append("9");
if(ae.getSource() == button[3]) {
//add function[0]
temporary[0] = Double.parseDouble(display.getText());
function[0] = true;
display.setText("");
}
if(ae.getSource() == button[4])
display.append("4");
if(ae.getSource() == button[5])
display.append("5");
if(ae.getSource() == button[6])
display.append("6");
if(ae.getSource() == button[7]) {
//subtract function[1]
temporary[0] = Double.parseDouble(display.getText());
function[1] = true;
display.setText("");
}
if(ae.getSource() == button[8])
display.append("1");
if(ae.getSource() == button[9])
display.append("2");
if(ae.getSource() == button[10])
display.append("3");
if(ae.getSource() == button[11]) {
//multiply function[2]
temporary[0] = Double.parseDouble(display.getText());
function[2] = true;
display.setText("");
}
if(ae.getSource() == button[12])
display.append(".");
if(ae.getSource() == button[13]) {
//divide function[3]
temporary[0] = Double.parseDouble(display.getText());
function[3] = true;
display.setText("");
}
if(ae.getSource() == button[14])
clear();
if(ae.getSource() == button[15])
getSqrt();
if(ae.getSource() == button[16])
getPosNeg();
if(ae.getSource() == button[17])
getResult();
if(ae.getSource() == button[18])
display.append("0");
}
public static void main(String[] arguments) {
Calculator c = new Calculator();
}
}
//the gui has close button so I didn't code that and < button has not been coded since the use of C
button..... thankyou

More Related Content

Similar to Hello, I need some assistance in writing a java program THAT MUST US.pdf

Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Mario Fusco
 
Operating system labs
Operating system labsOperating system labs
Operating system labs
bhaktisagar4
 
C++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdfC++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdf
Rahul04August
 
.net progrmming part2
.net progrmming part2.net progrmming part2
.net progrmming part2
Dr.M.Karthika parthasarathy
 
C++ Course - Lesson 2
C++ Course - Lesson 2C++ Course - Lesson 2
C++ Course - Lesson 2Mohamed Ahmed
 
Python From Scratch (1).pdf
Python From Scratch  (1).pdfPython From Scratch  (1).pdf
Python From Scratch (1).pdf
NeerajChauhan697157
 
Question Hello, I need some assistance in writing a java pr...Hel.pdf
Question Hello, I need some assistance in writing a java pr...Hel.pdfQuestion Hello, I need some assistance in writing a java pr...Hel.pdf
Question Hello, I need some assistance in writing a java pr...Hel.pdf
hainesburchett26321
 
Developer Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duoDeveloper Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duo
The Software House
 
BCSL 058 solved assignment
BCSL 058 solved assignmentBCSL 058 solved assignment
07012023.pptx
07012023.pptx07012023.pptx
07012023.pptx
NareshBopparathi1
 
4. functions
4. functions4. functions
4. functions
PhD Research Scholar
 
Write a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdfWrite a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdf
arri2009av
 
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
rushabhshah600
 
More instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docxMore instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docx
gilpinleeanna
 
public class TrequeT extends AbstractListT { .pdf
  public class TrequeT extends AbstractListT {  .pdf  public class TrequeT extends AbstractListT {  .pdf
public class TrequeT extends AbstractListT { .pdf
info30292
 
Gentle Introduction to Functional Programming
Gentle Introduction to Functional ProgrammingGentle Introduction to Functional Programming
Gentle Introduction to Functional Programming
Saurabh Singh
 
Leet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm ProblemsLeet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm Problems
Sunil Yadav
 

Similar to Hello, I need some assistance in writing a java program THAT MUST US.pdf (20)

Arrays
ArraysArrays
Arrays
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...
 
Operating system labs
Operating system labsOperating system labs
Operating system labs
 
C++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdfC++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdf
 
.net progrmming part2
.net progrmming part2.net progrmming part2
.net progrmming part2
 
C++ Course - Lesson 2
C++ Course - Lesson 2C++ Course - Lesson 2
C++ Course - Lesson 2
 
Python From Scratch (1).pdf
Python From Scratch  (1).pdfPython From Scratch  (1).pdf
Python From Scratch (1).pdf
 
Question Hello, I need some assistance in writing a java pr...Hel.pdf
Question Hello, I need some assistance in writing a java pr...Hel.pdfQuestion Hello, I need some assistance in writing a java pr...Hel.pdf
Question Hello, I need some assistance in writing a java pr...Hel.pdf
 
Qno 1 (d)
Qno 1 (d)Qno 1 (d)
Qno 1 (d)
 
Developer Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duoDeveloper Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duo
 
Algorithms with-java-1.0
Algorithms with-java-1.0Algorithms with-java-1.0
Algorithms with-java-1.0
 
BCSL 058 solved assignment
BCSL 058 solved assignmentBCSL 058 solved assignment
BCSL 058 solved assignment
 
07012023.pptx
07012023.pptx07012023.pptx
07012023.pptx
 
4. functions
4. functions4. functions
4. functions
 
Write a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdfWrite a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdf
 
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
 
More instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docxMore instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docx
 
public class TrequeT extends AbstractListT { .pdf
  public class TrequeT extends AbstractListT {  .pdf  public class TrequeT extends AbstractListT {  .pdf
public class TrequeT extends AbstractListT { .pdf
 
Gentle Introduction to Functional Programming
Gentle Introduction to Functional ProgrammingGentle Introduction to Functional Programming
Gentle Introduction to Functional Programming
 
Leet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm ProblemsLeet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm Problems
 

More from FashionColZone

In order to determine the overall chromosome map for E. coli, four Hf.pdf
In order to determine the overall chromosome map for E. coli, four Hf.pdfIn order to determine the overall chromosome map for E. coli, four Hf.pdf
In order to determine the overall chromosome map for E. coli, four Hf.pdf
FashionColZone
 
In a fantasy world where organisms can augment diffusion by using ma.pdf
In a fantasy world where organisms can augment diffusion by using ma.pdfIn a fantasy world where organisms can augment diffusion by using ma.pdf
In a fantasy world where organisms can augment diffusion by using ma.pdf
FashionColZone
 
Explain how consumer judges the quality of service (Including price .pdf
Explain how consumer judges the quality of service (Including price .pdfExplain how consumer judges the quality of service (Including price .pdf
Explain how consumer judges the quality of service (Including price .pdf
FashionColZone
 
Early Americans did not practice equality according to today’s defin.pdf
Early Americans did not practice equality according to today’s defin.pdfEarly Americans did not practice equality according to today’s defin.pdf
Early Americans did not practice equality according to today’s defin.pdf
FashionColZone
 
Do you think that the level of prosperity of a given society influen.pdf
Do you think that the level of prosperity of a given society influen.pdfDo you think that the level of prosperity of a given society influen.pdf
Do you think that the level of prosperity of a given society influen.pdf
FashionColZone
 
Design a circuit that detect the sequence 0110. Draw the Moore sta.pdf
Design a circuit that detect the sequence 0110. Draw the Moore sta.pdfDesign a circuit that detect the sequence 0110. Draw the Moore sta.pdf
Design a circuit that detect the sequence 0110. Draw the Moore sta.pdf
FashionColZone
 
Cyanide is a potent toxin that can kill a human in minutes. It funct.pdf
Cyanide is a potent toxin that can kill a human in minutes. It funct.pdfCyanide is a potent toxin that can kill a human in minutes. It funct.pdf
Cyanide is a potent toxin that can kill a human in minutes. It funct.pdf
FashionColZone
 
A Fullerene is a 3-regular planar graph with faces of degree 5 and 6.pdf
A Fullerene is a 3-regular planar graph with faces of degree 5 and 6.pdfA Fullerene is a 3-regular planar graph with faces of degree 5 and 6.pdf
A Fullerene is a 3-regular planar graph with faces of degree 5 and 6.pdf
FashionColZone
 
Assume that the paired date came from a population that is normally .pdf
Assume that the paired date came from a population that is normally .pdfAssume that the paired date came from a population that is normally .pdf
Assume that the paired date came from a population that is normally .pdf
FashionColZone
 
Briefly describe three processing schema used in cochlear implants..pdf
Briefly describe three processing schema used in cochlear implants..pdfBriefly describe three processing schema used in cochlear implants..pdf
Briefly describe three processing schema used in cochlear implants..pdf
FashionColZone
 
A satellite moves in a circular orbit around Earth at a speed of 470.pdf
A satellite moves in a circular orbit around Earth at a speed of 470.pdfA satellite moves in a circular orbit around Earth at a speed of 470.pdf
A satellite moves in a circular orbit around Earth at a speed of 470.pdf
FashionColZone
 
7. What do we mean by “spreading signal”in CDMA systems16. Name a.pdf
7. What do we mean by “spreading signal”in CDMA systems16. Name a.pdf7. What do we mean by “spreading signal”in CDMA systems16. Name a.pdf
7. What do we mean by “spreading signal”in CDMA systems16. Name a.pdf
FashionColZone
 
You will write a multi-interface version of the well-known concentra.pdf
You will write a multi-interface version of the well-known concentra.pdfYou will write a multi-interface version of the well-known concentra.pdf
You will write a multi-interface version of the well-known concentra.pdf
FashionColZone
 
You are interested in using the plasmid pGEE as a vector for incorpor.pdf
You are interested in using the plasmid pGEE as a vector for incorpor.pdfYou are interested in using the plasmid pGEE as a vector for incorpor.pdf
You are interested in using the plasmid pGEE as a vector for incorpor.pdf
FashionColZone
 
Why animals migrate I need 5 new ideas (exclude reproduction , s.pdf
Why animals migrate  I need 5 new ideas (exclude  reproduction , s.pdfWhy animals migrate  I need 5 new ideas (exclude  reproduction , s.pdf
Why animals migrate I need 5 new ideas (exclude reproduction , s.pdf
FashionColZone
 
Which of the following characteristics of the fetus distinguishes it.pdf
Which of the following characteristics of the fetus distinguishes it.pdfWhich of the following characteristics of the fetus distinguishes it.pdf
Which of the following characteristics of the fetus distinguishes it.pdf
FashionColZone
 
What are the major sources of cash (inflows) in a statement of cash .pdf
What are the major sources of cash (inflows) in a statement of cash .pdfWhat are the major sources of cash (inflows) in a statement of cash .pdf
What are the major sources of cash (inflows) in a statement of cash .pdf
FashionColZone
 
TYPES OF AUDIT1. Is there an internal audit function within your o.pdf
TYPES OF AUDIT1. Is there an internal audit function within your o.pdfTYPES OF AUDIT1. Is there an internal audit function within your o.pdf
TYPES OF AUDIT1. Is there an internal audit function within your o.pdf
FashionColZone
 
The total exergy is an extensive property of a system. True or False.pdf
The total exergy is an extensive property of a system. True or False.pdfThe total exergy is an extensive property of a system. True or False.pdf
The total exergy is an extensive property of a system. True or False.pdf
FashionColZone
 
1.Define culture. How can culture be conceptionalized Your resp.pdf
1.Define culture. How can culture be conceptionalized Your resp.pdf1.Define culture. How can culture be conceptionalized Your resp.pdf
1.Define culture. How can culture be conceptionalized Your resp.pdf
FashionColZone
 

More from FashionColZone (20)

In order to determine the overall chromosome map for E. coli, four Hf.pdf
In order to determine the overall chromosome map for E. coli, four Hf.pdfIn order to determine the overall chromosome map for E. coli, four Hf.pdf
In order to determine the overall chromosome map for E. coli, four Hf.pdf
 
In a fantasy world where organisms can augment diffusion by using ma.pdf
In a fantasy world where organisms can augment diffusion by using ma.pdfIn a fantasy world where organisms can augment diffusion by using ma.pdf
In a fantasy world where organisms can augment diffusion by using ma.pdf
 
Explain how consumer judges the quality of service (Including price .pdf
Explain how consumer judges the quality of service (Including price .pdfExplain how consumer judges the quality of service (Including price .pdf
Explain how consumer judges the quality of service (Including price .pdf
 
Early Americans did not practice equality according to today’s defin.pdf
Early Americans did not practice equality according to today’s defin.pdfEarly Americans did not practice equality according to today’s defin.pdf
Early Americans did not practice equality according to today’s defin.pdf
 
Do you think that the level of prosperity of a given society influen.pdf
Do you think that the level of prosperity of a given society influen.pdfDo you think that the level of prosperity of a given society influen.pdf
Do you think that the level of prosperity of a given society influen.pdf
 
Design a circuit that detect the sequence 0110. Draw the Moore sta.pdf
Design a circuit that detect the sequence 0110. Draw the Moore sta.pdfDesign a circuit that detect the sequence 0110. Draw the Moore sta.pdf
Design a circuit that detect the sequence 0110. Draw the Moore sta.pdf
 
Cyanide is a potent toxin that can kill a human in minutes. It funct.pdf
Cyanide is a potent toxin that can kill a human in minutes. It funct.pdfCyanide is a potent toxin that can kill a human in minutes. It funct.pdf
Cyanide is a potent toxin that can kill a human in minutes. It funct.pdf
 
A Fullerene is a 3-regular planar graph with faces of degree 5 and 6.pdf
A Fullerene is a 3-regular planar graph with faces of degree 5 and 6.pdfA Fullerene is a 3-regular planar graph with faces of degree 5 and 6.pdf
A Fullerene is a 3-regular planar graph with faces of degree 5 and 6.pdf
 
Assume that the paired date came from a population that is normally .pdf
Assume that the paired date came from a population that is normally .pdfAssume that the paired date came from a population that is normally .pdf
Assume that the paired date came from a population that is normally .pdf
 
Briefly describe three processing schema used in cochlear implants..pdf
Briefly describe three processing schema used in cochlear implants..pdfBriefly describe three processing schema used in cochlear implants..pdf
Briefly describe three processing schema used in cochlear implants..pdf
 
A satellite moves in a circular orbit around Earth at a speed of 470.pdf
A satellite moves in a circular orbit around Earth at a speed of 470.pdfA satellite moves in a circular orbit around Earth at a speed of 470.pdf
A satellite moves in a circular orbit around Earth at a speed of 470.pdf
 
7. What do we mean by “spreading signal”in CDMA systems16. Name a.pdf
7. What do we mean by “spreading signal”in CDMA systems16. Name a.pdf7. What do we mean by “spreading signal”in CDMA systems16. Name a.pdf
7. What do we mean by “spreading signal”in CDMA systems16. Name a.pdf
 
You will write a multi-interface version of the well-known concentra.pdf
You will write a multi-interface version of the well-known concentra.pdfYou will write a multi-interface version of the well-known concentra.pdf
You will write a multi-interface version of the well-known concentra.pdf
 
You are interested in using the plasmid pGEE as a vector for incorpor.pdf
You are interested in using the plasmid pGEE as a vector for incorpor.pdfYou are interested in using the plasmid pGEE as a vector for incorpor.pdf
You are interested in using the plasmid pGEE as a vector for incorpor.pdf
 
Why animals migrate I need 5 new ideas (exclude reproduction , s.pdf
Why animals migrate  I need 5 new ideas (exclude  reproduction , s.pdfWhy animals migrate  I need 5 new ideas (exclude  reproduction , s.pdf
Why animals migrate I need 5 new ideas (exclude reproduction , s.pdf
 
Which of the following characteristics of the fetus distinguishes it.pdf
Which of the following characteristics of the fetus distinguishes it.pdfWhich of the following characteristics of the fetus distinguishes it.pdf
Which of the following characteristics of the fetus distinguishes it.pdf
 
What are the major sources of cash (inflows) in a statement of cash .pdf
What are the major sources of cash (inflows) in a statement of cash .pdfWhat are the major sources of cash (inflows) in a statement of cash .pdf
What are the major sources of cash (inflows) in a statement of cash .pdf
 
TYPES OF AUDIT1. Is there an internal audit function within your o.pdf
TYPES OF AUDIT1. Is there an internal audit function within your o.pdfTYPES OF AUDIT1. Is there an internal audit function within your o.pdf
TYPES OF AUDIT1. Is there an internal audit function within your o.pdf
 
The total exergy is an extensive property of a system. True or False.pdf
The total exergy is an extensive property of a system. True or False.pdfThe total exergy is an extensive property of a system. True or False.pdf
The total exergy is an extensive property of a system. True or False.pdf
 
1.Define culture. How can culture be conceptionalized Your resp.pdf
1.Define culture. How can culture be conceptionalized Your resp.pdf1.Define culture. How can culture be conceptionalized Your resp.pdf
1.Define culture. How can culture be conceptionalized Your resp.pdf
 

Recently uploaded

Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
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
 
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
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
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
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
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
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 

Recently uploaded (20)

Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
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 ...
 
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...
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
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.
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 

Hello, I need some assistance in writing a java program THAT MUST US.pdf

  • 1. Hello, I need some assistance in writing a java program THAT MUST USE 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
  • 2. 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 javax.swing.*; import java.awt.event.*; public class Calculator extends JFrame implements ActionListener { JPanel[] row = new JPanel[5]; JButton[] button = new JButton[19]; String[] buttonString = {"7", "8", "9", "+", "4", "5", "6", "-", "1", "2", "3", "*",
  • 3. ".", "/", "C", "", "+/-", "=", "0"}; int[] dimW = {300,45,100,90}; int[] dimH = {35, 40}; Dimension displayDimension = new Dimension(dimW[0], dimH[0]); Dimension regularDimension = new Dimension(dimW[1], dimH[1]); Dimension rColumnDimension = new Dimension(dimW[2], dimH[1]); Dimension zeroButDimension = new Dimension(dimW[3], dimH[1]); boolean[] function = new boolean[4]; double[] temporary = {0, 0}; JTextArea display = new JTextArea(1,20); Font font = new Font("Times new Roman", Font.BOLD, 14); Calculator() { super("Calculator"); setDesign(); setSize(380, 250); setResizable(false); setDefaultCloseOperation(EXIT_ON_CLOSE); GridLayout grid = new GridLayout(5,5); setLayout(grid); for(int i = 0; i < 4; i++) function[i] = false; FlowLayout f1 = new FlowLayout(FlowLayout.CENTER); FlowLayout f2 = new FlowLayout(FlowLayout.CENTER,1,1); for(int i = 0; i < 5; i++) row[i] = new JPanel(); row[0].setLayout(f1); for(int i = 1; i < 5; i++) row[i].setLayout(f2); for(int i = 0; i < 19; i++) { button[i] = new JButton(); button[i].setText(buttonString[i]);
  • 4. button[i].setFont(font); button[i].addActionListener(this); } display.setFont(font); display.setEditable(false); display.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); display.setPreferredSize(displayDimension); for(int i = 0; i < 14; i++) button[i].setPreferredSize(regularDimension); for(int i = 14; i < 18; i++) button[i].setPreferredSize(rColumnDimension); button[18].setPreferredSize(zeroButDimension); row[0].add(display); add(row[0]); for(int i = 0; i < 4; i++) row[1].add(button[i]); row[1].add(button[14]); add(row[1]); for(int i = 4; i < 8; i++) row[2].add(button[i]); row[2].add(button[15]); add(row[2]); for(int i = 8; i < 12; i++) row[3].add(button[i]); row[3].add(button[16]); add(row[3]); row[4].add(button[18]); for(int i = 12; i < 14; i++) row[4].add(button[i]); row[4].add(button[17]);
  • 5. add(row[4]); setVisible(true); } public void clear() { try { display.setText(""); for(int i = 0; i < 4; i++) function[i] = false; for(int i = 0; i < 2; i++) temporary[i] = 0; } catch(NullPointerException e) { } } public void getSqrt() { try { double value = Math.sqrt(Double.parseDouble(display.getText())); display.setText(Double.toString(value)); } catch(NumberFormatException e) { } } public void getPosNeg() { try { double value = Double.parseDouble(display.getText()); if(value != 0) { value = value * (-1); display.setText(Double.toString(value)); } else { } } catch(NumberFormatException e) { } }
  • 6. public void getResult() { double result = 0; temporary[1] = Double.parseDouble(display.getText()); String temp0 = Double.toString(temporary[0]); String temp1 = Double.toString(temporary[1]); try { if(temp0.contains("-")) { String[] temp00 = temp0.split("-", 2); temporary[0] = (Double.parseDouble(temp00[1]) * -1); } if(temp1.contains("-")) { String[] temp11 = temp1.split("-", 2); temporary[1] = (Double.parseDouble(temp11[1]) * -1); } } catch(ArrayIndexOutOfBoundsException e) { } try { if(function[2] == true) result = temporary[0] * temporary[1]; else if(function[3] == true) result = temporary[0] / temporary[1]; else if(function[0] == true) result = temporary[0] + temporary[1]; else if(function[1] == true) result = temporary[0] - temporary[1]; display.setText(Double.toString(result)); for(int i = 0; i < 4; i++) function[i] = false; } catch(NumberFormatException e) { } } public final void setDesign() { try { UIManager.setLookAndFeel(
  • 7. "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); } catch(Exception e) { } } @Override public void actionPerformed(ActionEvent ae) { if(ae.getSource() == button[0]) display.append("7"); if(ae.getSource() == button[1]) display.append("8"); if(ae.getSource() == button[2]) display.append("9"); if(ae.getSource() == button[3]) { //add function[0] temporary[0] = Double.parseDouble(display.getText()); function[0] = true; display.setText(""); } if(ae.getSource() == button[4]) display.append("4"); if(ae.getSource() == button[5]) display.append("5"); if(ae.getSource() == button[6]) display.append("6"); if(ae.getSource() == button[7]) { //subtract function[1] temporary[0] = Double.parseDouble(display.getText()); function[1] = true; display.setText(""); } if(ae.getSource() == button[8]) display.append("1"); if(ae.getSource() == button[9]) display.append("2"); if(ae.getSource() == button[10])
  • 8. display.append("3"); if(ae.getSource() == button[11]) { //multiply function[2] temporary[0] = Double.parseDouble(display.getText()); function[2] = true; display.setText(""); } if(ae.getSource() == button[12]) display.append("."); if(ae.getSource() == button[13]) { //divide function[3] temporary[0] = Double.parseDouble(display.getText()); function[3] = true; display.setText(""); } if(ae.getSource() == button[14]) clear(); if(ae.getSource() == button[15]) getSqrt(); if(ae.getSource() == button[16]) getPosNeg(); if(ae.getSource() == button[17]) getResult(); if(ae.getSource() == button[18]) display.append("0"); } public static void main(String[] arguments) { Calculator c = new Calculator(); } } //the gui has close button so I didn't code that and < button has not been coded since the use of C button..... thankyou