Fourth Lab

27 Dec 2021 - 17:25 | Version 1 |

Learning Objective(s)

  1. Learn the for loop
  2. Be able nest loops
  3. Be able to format output well
  4. Use a switch statement
  5. Learn something on your own.

Overview of the Program

This lab involves creating an arithmetic table. You are to allow the user to specify which operation (+, -, *, /) and the size of the table.

Specifics

Major components

  1. The program should be called Tables
  2. The user will input a letter/word indicating which operation (add, subtract, multiply, divide). But they may misspell it and/or allowed to use upper or lower case letters. So only use the first letter.
  3. Use integer arithmetic for all the operations.
  4. The user can specify the size of the table (up to 99)
  5. The table must be nicely aligned

Things to learn on your own

Google can be a significant help here. Also, your textbooks can help.
  1. How to get the first letter of the string
  2. How to format the output with a variable amount of spaces

Sample output

Simplest sample result if it is an addition table for 1 - 5 is as follows. Feel free to make your table even nicer if you want.
   +   1   2   3   4   5
   1   2   3   4   5   6
   2   3   4   5   6   7
   3   4   5   6   7   8
   4   5   6   7   8   9 
   5   6   7   8   9  10

Submission

  1. Create an empty zip folder.
  2. Place your program (.java file) in it
  3. Place your software development report in it.
  4. Submit the zip folder on canvas

Optional improvements

  1. Add an additional operation
  2. Allow for floating point in the division (outputting at most 3 digits are the decimal point)
  3. Work in base 8 (doing all base work yourself). This is a MAJOR challenge and is only included for those that are extremely bored!
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