Assignment: Design a simple GUI calculator using the stack data structure to per
ID: 3654660 • Letter: A
Question
Assignment: Design a simple GUI calculator using the stack data structure to perform additions, subtractions, multiplications and divisions. (stuff like pop, bush TOS, etc.) The calculator window should have at least two panels - one for display and the other for buttons (0 - 9, . , +, -, X, /, =, C). After an expression is entered, its postfix or prefix is displayed and then the result. Have 3 classes. One main class. A stack class, and a GUI calculator class. The main is going to be smallest one obviously. and the GUI calculator is going to have the GUI layout design, but my question is how do i use stacks to do this. Can someone please write these codes for me, Id very much appreciate it. Thank you in advance.Explanation / Answer
import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; import java.util.Stack; public class JCalculator implements ActionListener { JFrame jfrm; JFrame jfrm2; JTextField txt; JLabel results; String str = ""; Stack operands = new Stack(); char[] a = new char[0]; int used = 0; JCalculator(){ jfrm = new JFrame("JCalc"); jfrm.getContentPane().setLayout(new GridLayout(0,1)); jfrm.setSize(210,210); results = new JLabel("",SwingConstants.RIGHT); jfrm.getContentPane().add(results); jfrm.setLocation(400,300); jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton[] calbut= new JButton[14]; String []but = {"7","8","9","/","4","5","6","*","1","2","3","-","0","C" }; JButton equal = new JButton("="); JButton add = new JButton("+"); JPanel jbutton = new JPanel(); jbutton.setLayout(new GridLayout(4,3)); for(int i=0; iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.