Question
Show a GUI calculator program that will offer the user a button to clear the values, buttons for all digits 0 through 9, as well
Show a GUI calculator program that will offer the user a button to clear the values, buttons for all digits 0 through 9, as well as the operator buttons for multiplication, division, addition, subtraction, and equal. The user should be able to click the various digit buttons and have them display combined as a single number in a textbox or label control. (e.g., if the user clicks the 2, 4 and 7 buttons successively the textbox or label should display 247) If the user clicks on an operator button the current value must be included in the running total based on the last operator button clicked. If no operator button has been clicked since the start of the program or since the last time the clear button has been clicked, then the current value will be added to the total by default. When the equal button is clicked, the current value will be added or subtracted from the total per the previous operator button and then the final total will be displayed in the textbox or label. Note: As mentioned, you can choose to use either a textbox or a label control for displaying data but whichever you choose, only one should be used. (All of this mimics a standard calculator that you have used before.)
- program should display a form with either a textbox or label control across the top. Below that, the form should display the buttons described in the description above.
- Name all controls suitable names. Hint: prefixes can makecontrol names easier to distinguish one from the other. Examplesinclude cmd for command button, txt for textbox, and lbl for label.Standard naming conventions are common in the software development field.
- All buttons should be the same size and neatly aligned in a grid pattern below the textbox/label. How you layout the grid is up to you but I would recommend sticking with the standard pattern for calculators. If you would like your operator buttons to be a different size from your digit buttons that is fine but all operator buttons should be the same size and all digit buttons should be the same size. All buttons should display their value on their face and be centered.
- Define any variables you need to keep up with what operator was last clicked as well as the running total. Hint: This can be done with one variable for the total and one variable to indicate the last operator clicked.
- Using events for the buttons, add functionality to each button.
- Digit buttons should append their respective digit to the end of the displayed number.
- Operator buttons should call for currently displayed value to be added or subtracted per the last operator called and then set the operator "flag" variable to indicate what was just clicked. Either the operator button's code or the next digit button clicked will need to clear the display.
- The equal button should call for the last operation to be completed just as the other operators do, then display the final total in the textbox/label control.
- The clear button should clear the textbox/label, (either make it blank or make it display 0), as well as reset all variables as they were when the program began.
EXPECTED OUTPUT
A working calculator for multiplication, division, addition, and subtraction.
Program 2:
The program for this Assessment will consist of two sections, each headed by the three-line comment below:
//*********************************************************
//**** Program 2 Section X
//*********************************************************
(where X stands for the portion of the program to follow)
Section 1:
- Enter the comment with the section title as described above.
- You will show a two-dimensional string array of 4x4 elements named salesRegions.
- The first column of the array will contain the names of the sales regions, North, South, East, and West. Columns 2, 3, and 4 will contain the names of the personnel in charge of those sales regions and are listed below. Fill the array with this data.
North | South | East | West |
Bob | Sue | Nathan | Wanda |
Stef | Janice | Henry | Charles |
Ron | Will | Kimmy | Pete |
- Print to the console the statement, "Section 1: Two-dimensional Array."
- Using nested loops, display the contents of the array by sales region. (See the expected output for an example.)
Section 2:
- Enter the comment with the section title as described above.
- show an arraylist called salesTeam. The arraylist will contain the names of the sales team members responsible for the sales in that region. (Hint: This is using the collection tool, arraylist, and is not a standard array like the two-dimensional array in section 1.)
- Once created, use the two-dimensional array to add the names in the North region to the salesTeam arraylist. (Notice: You are just adding the names of the people, not the name of the region. So, in this case the names added should be Bob, Stef, and Ron.)
- Print to the console a blank line and the statement, "Section 2: Array List."
- Using the methods available in the arraylist class, display the current number of elements in the salesTeam arraylist.
- Next, add the names of the people from the South region to the salesTeam arraylist.
- Using the appropriate method available in the arraylist class, check to see if "Stef" is in the salesTeam arraylist and print a statement as to whether or not Stef is in the list.
- Display the number of items in the salesTeam arraylist.
- Remove Janice and Ron from the salesTeam arraylist.
- Display the number of items in the salesTeam arraylist.
- Using a loop, display "Names currently in the salesTeam arraylist." followed by all the elements remaining in the salesTeam arraylist.
EXPECTED OUTPUT
Section 1: Two-dimensional Array.
North
Bob
Stef
Ron
South
Sue
Janice
Will
East
Nathan
Henry
Kimmy
West
Wanda
Charles
Pete
Section 2: Array List.
There are 3 names in the salesTeam arraylist.
Stef is in the salesTeam arraylist.
There are 6 names in the salesTeam arraylist.
There are 4 names in the salesTeam arraylist.
Names currently in the salesTeam arraylist.
Bob
Stef
Sue
Will
Program 3:
The program for this Assessment will consist of five sections, each headed by the three-line comment below:
//*********************************************************
//**** Program 3 Section X
//*********************************************************
(where X stands for the portion of the program to follow.)
Section 1:
- Enter the comment with the section title as described above.
- CarDealz used cars wants to build an app for their buyers to know what cars are on the approved list for purchase. You will show a structure with the string fields for Make and Model and one integer field ModelYear for the earliest acceptable model year for that car.
- Show an array of these structures. For testing purposes, we will begin with three and the values for them will be {Ford, Mustang, 2010}, {Chevrolet, Silverado, 2008}, and {Dodge, Charger, 2012}.
- Print to the console the statement, "Section 1: Array of Structures."
- Using a loop, display the full contents of each structure in the array.
Section 2:
- Enter the comment with the section title as described above.
- The app from section 1 needs a means to check to see how many of each model CarDealz already has on the lot so that the buyers do not show a glut of any one model. In this section, you will show a dictionary named inventoryCount that will use the car model as the key and the inventory quantity as the value.
- Populate your dictionary with the following values:
Mustang | 9 |
Silverado | 13 |
Charger | 4 |
- Print to the console a blank line and the statement, "Section 2: Inventory Count."
- Using the methods available in the dictionary class, display the current number of each model in the inventoryCount dictionary.
Section 3:
- Enter the comment with the section title as described above.
- You are thinking of adding array lists for different work weeks to the CarDealz app because not all employees work the same days of the week. Show an arraylist called DaysofWeek and add all the days of the week to it.
- Print to the console the statement, "Section 3: Days of the Week."
- Using a loop, display the days from the arraylist.
- Using a loop, display the days from the arraylist in reverse order.
- Show a second arraylist called WorkDays and copy the DaysofWeek arraylist to it.
- Delete "Saturday" and "Sunday" from the WorkDays arraylist.
- Print the contents of WorkDays.
Section 4:
- Enter the comment with the section title as described above.
- There is further discussion about features to be added to the CarDealz app at a later time. You think it is best that you get some practice with stacks and queues as you think you will likely need them.
- Print to the console the statement, "Section 4: Stack."
- Show a stack.
- Using your stack, push the following values: 10,24,31,45,19, 76
- Using methods of the stack class, print a message telling howmanyitemsareonthe stack.
- Pop three items off of the stack and repeat your printed message telling how many items are in the stack.
- Display the next item in the stack to be popped.
Section 5:
- Enter the comment with the section title as described above.
- Print to the console the statement, "Section 5: Queue"
- Show a queue.
- Using your queue, enqueue the following values: 10,24,31,45,19,76
- Using methods of the queue class, print a message telling howmanyitemsareonthe queue.
- Dequeue three items off of the queue and repeat your printed message telling how many items are in the queue.
- Display the next item in the queue to be dequeued.
EXPECTED OUTPUT
Section 1: Array of Structures
Ford, Mustang, 2010
Chevrolet, Silverado, 2008
Dodge, Charger, 2012
Section 2: Inventory Count.
There are 9 Mustangs.
There are 13 Silverados.
There are 4 Chargers.
Section 3: Days of the Week
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Saturday
Friday
Thursday
Wednesday
Tuesday
Monday
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Section 4: Stack
There are 6 items in the stack.
There are 3 items in the stack.
The next item to be popped from the stack is 31.
Section 5: Queue
There are 6 items in the queue.
There are 3 items in the queue.
The next item to be dequeued from the queue is 45.
Program 4:
he program for this Assessment will consist of three sections, each headed by the three-line comment below:
//*********************************************************
//**** Program 4 Section X
//*********************************************************
(where X stands for the portion of the program to follow.)
Section 1:
- Enter the comment with the section title as described above.
- ShowanarrayListnamedproduceList.
- ProduceListisusedtoholdthedescriptionandpriceofanitem. Addthefollowingdatatothe producelist:
- bananas0.59
- grapes2.99
- apples1.49
- pears1.39
- lettuce0.99
- onions0.79
- potatoes0.59
- peaches1.59
- Show thedatafromproduceListto afilecalledProducePrice.
- Showafunction, namedFileLineCount(), that returns an integer and accepts a string. Pass the function the file name. It shouldthenuseawhilelooptoreturnthenumberoflinesinafile. Hint: The function will be reading the file you just created above.
- Callthefunction, FileLineCount(),anddisplayits return value as the number of items in the file using the following format: "Therearexxproductsinthefile." Where xx is the number returned by FileLineCount().
Section 2:
- Enter the comment with the section title as described above.
- YouwilladdfourmoreitemstotheProducePrice.txt file.Theyareasfollows: peppers 0.99 celery 1.29 cabbage 0.79 tomatoes 1.19
- Callthefunction, FileLineCount(),anddisplayits return value as the number of items in the file using the following format: "Therearexxproductsinthefile." Where xx is the number returned by FileLineCount().
Section 3:
- Enter the comment with the section title as described above.
- Using a loop, readthecontentsofthefileProducePrice.txtintoa newarraylistcalledproducePrices.
- After populating the producePrices arraylist, loop through it and print its contents, inserting a line number for each item.
- Usingthecount propertyoftheproducelist, displaytheoutputinthefollowingformat: "TherearexxproductsintheproducePrices list."
EXPECTED OUTPUT
Thereare8productsinthefile.
Thereare12productsinthefile.
- bananas0.59
- grapes2.99
- apples1.49
- pears1.39
- lettuce0.99
- onions0.79
- potatoes0.59
- peaches1.59
- peppers0.99
- celery1.29
- cabbage0.79
- tomatoes1.19
Thereare12productsintheproducePrices list.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Answer Program 1 GUI Calculator import javaxswing import jav...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started