In this homework, you will create a calculator with 4 cores, i.e. the calculator can evaluate...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
In this homework, you will create a calculator with 4 cores, i.e. the calculator can evaluate 4 mathematical expressions in parallel Problem 1: Implement class Calculator with the interface as follow: Calculator 12+8*4 cpu 1 cpu 2 cpu 3 cpu 4 0 3 6 9 Clear 1 7 Del ☐ 2 5 8 + 1 X 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 mathe- matical 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 • panell: contains a JTextArea to display mathematical expressions, uses a default layout. • panel2: contains 4 JButtons to compute mathematical expressions and 4 JTextAreas to display results. panel2 use a grid layout. • These 5 JText Areas are set to be un-editable. • panel3: use a border layout to contain panell and panel2. Put panell 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 JText Area 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 action Performed (Action Event 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 inde- pendently. Specifically • When a CPU button is pressed, the expression is sent to this CPU. Your program should eval- uation 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 Calculator Thread to extend the Thread class private class CalculatorThread extends Thread { } //some data members // constructor: public Calculator Thread (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 action Performed (ActionEvent e) { // Your implementation: Check which CPU button is pressed, // then create and run a Calculator Thread 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. 3 In this homework, you will create a calculator with 4 cores, i.e. the calculator can evaluate 4 mathematical expressions in parallel Problem 1: Implement class Calculator with the interface as follow: Calculator 12+8*4 cpu 1 cpu 2 cpu 3 cpu 4 0 3 6 9 Clear 1 7 Del ☐ 2 5 8 + 1 X 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 mathe- matical 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 • panell: contains a JTextArea to display mathematical expressions, uses a default layout. • panel2: contains 4 JButtons to compute mathematical expressions and 4 JTextAreas to display results. panel2 use a grid layout. • These 5 JText Areas are set to be un-editable. • panel3: use a border layout to contain panell and panel2. Put panell 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 JText Area 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 action Performed (Action Event 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 inde- pendently. Specifically • When a CPU button is pressed, the expression is sent to this CPU. Your program should eval- uation 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 Calculator Thread to extend the Thread class private class CalculatorThread extends Thread { } //some data members // constructor: public Calculator Thread (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 action Performed (ActionEvent e) { // Your implementation: Check which CPU button is pressed, // then create and run a Calculator Thread 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. 3
Expert Answer:
Answer rating: 100% (QA)
Below is a basic implementation of the classes described in your problem statement Please note that the code may need further adjustments based on your specific requirements and the GUI library you ar... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
In this assignment, you will create a program that allows theuser to draw in a window using brushes of different sizes andcolors. The user will be able to change the size and color of thebrush using...
-
The drawing shows a frictionless incline and pulley. The two blocks are connected by a wire (mass per unit length = 0.0250 kg/m) and remain stationary. A transverse wave on the wire has a speed of...
-
What are the steps in the problem-solving process?
-
The city of Mumbai in India imposed rent controls on apartments in 1947. Despite inflation and changes in land value, allowable rents have hardly increased since that time! Use what you know about...
-
The following information was taken from the records of Mobile Motorsports, Ince, at September 30, 2008. Requirement Prepare a multistep income statement for Mobile Motorsports, Inc., for the fiscal...
-
The trial balance of Ogilvys Boutique at December 31 shows Inventory $21,000, Sales Revenue $156,000, Sales Returns and Allowances $4,000, Sales Discounts $3,000, Cost of Goods Sold $92,400, Interest...
-
What specific programming, stations (radio, TV and cable networks), digital assets that will help get a disc golf establishment known to millennials living in Phoenix Arizona and why would these...
-
Consider an infinite 1D chain of H 2 molecules where the molecular axis is oriented perpendicular to the chain direction, as shown below. (a) How many bands are there in the band structure? (b)...
-
A two-way slab floor system as shown below. Concrete strength fc =25MPa and steel yield strength is fy=420MPa. Service live load is 2.0 kN/m and additional dead load is 4.0 kN/m. Story height is...
-
Fill in the missing information in the following table. Assume that Portfolio AB is 60 percent invested in Stock A. (Round your answer to 2 decimal places. Negative amounts should be Indicated by a...
-
Write a program (C++) that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits. Example: Input: 3456 Output: 3 4 5 6 Sum of digits...
-
A batch distillation process is used to reclaim a mixture of water (HO) and hydrogen peroxide (HO) used for the wet etching of tungsten from silicon wafers. Water is the more volatile component....
-
1 . Although we re capable of understanding speech at rates up to 6 0 0 words per minute, the average person speaks much more slowly between _ _ _ _ _ and _ _ _ _ _ words per minute. a: 1 5 0 ; 2 0 0...
-
Harris Company manufactures and sells a single product. A partially completed schedule of the company's total costs and costs per unit over the relevant range of 59,000 to 99,000 units is given...
-
How many H atoms are in 3.4 g of C12H22O11? (A) 6.0 10^23 (B) 1.3 10^23 (C) 3.8 10^22 (D) 6.0 10^2 (The answer is B but why and how do you solve this problem and other like it.)
-
Don Griffin worked as an accountant at a local accounting firm for five years after graduating from university. Recently, he opened his own accounting practice, which he operates as a corporation....
-
David and Darlene Jasper have one child, Sam, who is 6 years old. The Jaspers reside at 4639 Honeysuckle Lane, Los Angeles, CA 90248. David's Social Security number is 577-11-3311, Darlene's is...
-
The following additional information is available for the Dr. Ivan and Irene Incisor family from Chapters 1-4. Ivan and Irene paid the following in 2012 (all by check or can otherwise be...
-
Ken paid the following amounts for interest during 2012: Qualified interest on home mortgage...........................................$4,700 Auto loan...
-
Describe the process of valuing the entrepreneurs ownership interest in a two-stage investment. Refer to Tables 13.10 and 13.13. Data from table 13.10 Data from table 13.13 Market potential...
-
Euro Exchange Rates. The exchange rate that we consider is the amount of euros that one can purchase for one U.S. dollar. We have \(T=699\) daily observations from the period April 1, 2005, through...
-
Evaluate the current yield curve level and structure using the following screens: a. YCRV or GC to access yield curves. b. FWCV to determine implied forward rates. c. USoo03M, USoo06M, USoo09M, and...
Study smarter with the SolutionInn App