Repetition Lab: Calculator: Fall 2024
Learning Objective(s)
- Enhance skills with constants
- Learn about event controlled loops (and use a priming read)
- Learn to use a switch statement
- Work with floating point, characters and string data types
- Statement coverage for testing
- Enhance overall programming skills
Overview of the Program
Write a program to simulate a simple calculator working with floating point arithmetic (+, -, *, /).
Specifics
- The program is to be called Calculator
- It is to allow for floating point arithmetic (double is probably best)
- There should be at least 5 characters constants (one for each operation and for the ending signal)
- ! is used to signal the end of the input
- After each operation, the current result should be displayed
- If an invalid operation is inputted, the user should be informed and then allowed to re-enter
- A priming read must be used
Sample dialogue
Below is a sample dialogue. The prompts may vary but the input given by the user is to be the same format. Your output can vary somewhat as long as the required data is nicely displayed.
What is the first number? 5
What operation (+, -, *, /, or ! to end)? +
What is your next number? 7
12.0
Next operation? t
That is an invalid option. Please re-enter. Next operation? -
What is your next number? 2.5
9.5
Next operation? !
You can also run a solution for this program if you want. See classroom instructions for more details.
Lab Hints
Submission
- Create a software development report
- For the system design, you may use my flowchart if it is the design of your program. Otherwise, you need to make your own.
- For testing report,
- make sure your tests ensure that each statement is executed at least one.
- your expected output CANNOT be pasted from the dialogue of a running. Only the actual output may be pasted
- It should contain two different inputs that are "errors"
- For the improvement section, specify how many points were lost from the last lab that you should not lose points for on this lab because you corrected the problem
- create a pdf document from your software development report
- create an empty zip folder
- place only Calculator.java and your pdf document into it
- submit the zip folder on canvas
Optional improvements
Optional improvements should ONLY be worked on once the program is completing working. In addition, the work is to be done on your own with little if any help for lab assistants or the instructor.
- Add an option to clear the current result (specified by a C)
- Add another arithmetic operation
- Allow the user to use different number bases (such as binary, octal, hex)
- Add the use of memory.
- Combine any and all optional improvements into one program (called CalculatorExtra.java) and add it to the zip folder before submitting it