Online College Courses for Credit

Assignment 12 – GUI Controls Memory Calculator

Assignment 12 – GUI Controls Memory Calculator

Author: l marshall

Click link for download:

This is the last homework assignment in this course, and it is meant to show you how a small butcomplete GUI application is structured. We will make our GUI actually control our memory calculator.To do this, you will need to create an instance of MemoryCalc in the CalcGUI and write event Handlersto pass information back and forth between the calculator and the GUI. There are many possible ways toachieve this, but the easiest is probably to develop four different event Handlers:DigitHandler – This event Handler is added to the 0-9 and . (dot) keys. If the equals button was justpressed, this event Handler will overwrite the total shown in the text field with the value of the key (itslabel) that was just pressed. If the equals button was not just pressed, this event Handler will appendthe current key's label onto the end of the string shown in the text field.OperatorHandler – This event Handler is added to the +, -, *, and / keys. It sets the value of a class fieldto the operator that the user has chosen.ClearHandler – This event Handler is added to the C key. It calls the calculator's clear method and setsthe value of the text field back to 0.0.EqualsHandler – This event Handler is added to the = key. It reads the current value from the text field,converts it to a double, and calls the appropriate calculator method based on the current operator,passing in the double value. The calculator will compute the answer, and then this event Handler willupdate the value in the text field to the calculator's current total.That is all that required for the homework assignment, however I also encourage you to play aroundwith the different types of calculators we have written in this course, perhaps after this course ends. Forinstance, you could add functionality for geometric operations like sine and cosine. Or you could createa Super Calculator that has different views for scalar, vector, and matrix calculations. Whatever youcome up with, I suggest you clean it up and document it. Potential employers always look favorably onbeing able to review code you have written and ask you questions about it.Hints:You can use the ActionEvent's getSource() method to get a reference to the button that was pressed,and you can use Button's getText() method to find out the label of that button.When the EqualsHandler is converting the text shown in the text field into a double value in order topass it to the calculator, be careful to handle the case where the text field contains an invalid value, suchas 6..72. In this case you should catch the exception, display an error message to the user, and abort thecall to the calculator (just restore the current total to the text field).The user should only be able to enter numbers between when an operator has been selected and whenthe equals button has been pushed. The DigitHandler should ignore any button presses when the GUI isnot in this state.Sample output:Please view the video homework.swf to see what the output of this topic's assignment should be.You will be graded according to the following rubric: Something happens when the user clicks on any of the keys of the calculator GUI – 2 points The user cannot enter a value without first choosing an operator – 2 points The user is able to enter numbers correctly (i.e. the previous total is overwritten when the userstarts a new number, and new digits are appended to the new number) – 2 points When the equals button is pressed, the appropriate calculator method is called based on theoperator the user has selected – 2 points When the equals button is pressed, the appropriate operand passed to the calculator method asan argument – 2 points When the equals button is pressed, the value in the text field is updated to the new total – 2points The clear button calls the calculator's clear method and updates the text field to 0.0 – 2 points If the user enters an invalid value, an error message is displayed – 2 points Your program compiles – 2 points Your program runs – 1 point You follow standard coding conventions (e.g. variable names, indentation, comments, etc.) –point

See More
Fast, Free College Credit

Developing Effective Teams

Let's Ride
*No strings attached. This college course is 100% free and is worth 1 semester credit.

37 Sophia partners guarantee credit transfer.

299 Institutions have accepted or given pre-approval for credit transfer.

* The American Council on Education's College Credit Recommendation Service (ACE Credit®) has evaluated and recommended college credit for 33 of Sophia’s online courses. Many different colleges and universities consider ACE CREDIT recommendations in determining the applicability to their course and degree programs.