Need Help with this Question or something similar to this? We got you! Just fill out the order form (follow the link below), and your paper will be assigned to an expert to help you ASAP.
Learning Goal: I’m working on a java multi-part question and need an explanation and answer to help me learn.Problem 1: Implement class Calculator with the interface as follow: Figure 1: Caption You will need some data members for your class, such as some arrays of JButtons, and JTextArea. The most needed data member is a string variable, named expression, to keep track of a mathematical expression. This variable is initialized as a string that contains “0” character. private String expression = “0”; You will need 4 JPanels to organize your calculator buttons • panel1: contains a JTextArea to display mathematical expressions, uses a default layout. 1 • panel2: contains 4 JButtons to compute mathematical expressions and 4 JTextAreas to display results. panel2 use a grid layout. • These 5 JTextAreas are set to be un-editable. • panel3: use a border layout to contain panel1 and panel2. Put panel1 at the top, and panel2 at the center of panel3 • panel4: uses a grid layout to display 10 digit buttons, dot button, 4 operation buttons (addition, subtraction, multiplication, and division), clear and delete buttons. • set hgap and vgap to be 3 pixels in these grid layouts. • set border layout to Calculator, then put panel3 and panel4 at the top and center of Calculator accordingly. You need the string variable expression to store and display mathematical expressions. The first JTextArea should work as follows • At the beginning, the top JTextArea displays 0. • As you push the digit, dot, or operation buttons, the JTextArea changes accordingly. • If you keep pushing 0 at the beginning, the display should not change, why? 0000 is still 0. • Replace the operator if you choose a different one. For example, the current expression “8*9+7*” will change to “8*9+7/” if you push the “/” button. • The expression is reset to 0 if the Clear button is pressed. • The Del button will delete the last letter in the expression. If there is one letter left, the Del button should reset the expression to 0. To perform the above button actions, you need to write an inner class NumberListener to implement the interface NumberListener, i.e. implement its actionPerformed() method private class NumberListener implements ActionListener { @ Override public void actionPerformed ( ActionEvent e ){…} } The mathematical expression will not be evaluated until one of the CPU buttons is pressed. You can assume that each CPU button represents an individual CPU that can do computation independently. Specifically • When a CPU button is pressed, the expression is sent to this CPU. Your program should evaluation this mathematical expression by calling method evaluation provided in the template. Do not modify this code, please. private double evaluation ( String expression ); 2 • The CPU button should be disabled for 5000 milliseconds right after it is pressed. You will need to call function setEnabled to set the Disability of JButtons. • During this computational time, the user can press other CPU buttons, or reset and enter other mathematical expressions, etc. i.e. your program is not frozen while a task is performed. • After 5000 milliseconds, the CPU button is enabled again and the next-sitting JTextArea will display the result. To carry out this task, you need to write inner class CalculatorThread to extend the Thread class private class CalculatorThread extends Thread { // some data members // constructor : public CalculatorThread ( String expression , JButton button , JTextArea textArea ){ // your implementation } @ Override public void run (){ // Your implementation : // 1. Disable the CPU button // 2. Evaluation the expression // 3. Put the thread to sleep for 5000 milliseconds // 4. Display the result in textArea // 5. Enable the CPU button } } Your class provides a constructor that takes three parameters: a String variable, a JButton, and a JTextArea. These parameters are used to initialize its data member and will be used again in the run() method. You also need to write an inner class CPUListener to implement the interface ActionListener and add this to each CPU button: private class CPUListener implements ActionListener { @ Override public void actionPerformed ( ActionEvent e ){ // Your implementation : Check which CPU button is pressed , // then create and run a CalculatorThread } } Problem 2: Implement class CalculatorApp to test the Calculator Create a JFrame with title “Calculator” and a Calculator with 4 CPU. Add the panel to the JFrame. Make sure that the JFrame appears normally. You can call methods pack() or setSize(int, int) to set the size to the JFrame.
Requirements: As clear as possible