Repetition: Spring 2024

23 Jan 2024 - 15:44 | Version 1 |

Learning Objective(s)

  1. Learn to use repetition with a priming read
  2. Learn to use a switch statement

Overview of the Program

For this lab you are to create a simple calculator that uses addition, subtraction, multiplication, and division. It will not have any order of precedence or ()'s.

Specifics

  • The program should be called Calculator
  • All arithmetic is to be integer arithmetic
  • The user is to input a +, -, *, or / to indicate what operation
  • If a wrong operation is given, the program should inform the user that a wrong operation was given and the number and operation be re-entered
  • The program should continue until an = is entered by the user.
  • The program must use a loop with a priming read
  • The program must use a switch statement to determine which operation and do the appropriate arithmetic.

Sample dialogue

Below is a sample dialogue. Your output can vary somewhat as long as the required data is nicely displayed
Please input operation and number (ex. + 5). Space is essential). To terminate, use = 
+ 7
- 2
* 4
/ 3
=
Result = 6
You can also run a solution for this program if you want. See classroom instructions for more details.

Submission

  1. Create your SDR.
    • In Lessons Learned, include a discussion on about priming reads and switch statement
    • Your testing should include at least 2 different types of errors and ensure that every line of code is executed at least once.
    • If you used any hints, be sure to indicate that in the Outside Resources Used section
  2. Convert your SDR into a pdf document
  3. Create an empty zip folder
  4. Place your java file and pdf document in it.
  5. Submit the zip folder on canvas

Hints

  1. Algorithm hint
  2. Priming reads

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.
  1. Allow for other operations. (Implementing the use of ()'s and/or precedence is way beyond the level of the programming covered this far in the course. Don't do it).
  2. Display the result as you go
  3. Allow the program to clear the current value and start over again.
  4. Add a memory function. One instruction for saving the current result to the clipboard. Another method for using that result (instead of an inputted number) for the operation. Also allow for the retrieving of the value in the clipboard.
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback
This website is using cookies. More info. That's Fine