600.108 Intro Programming Lab, Week 4

The Problem:

This week you are going to write a menu-driven program to process three types of transactions. The purpose is to get comfortable with different types of loops. Each transaction will perform a different operation on some data:

  1. Print all the letters between two given letters, inclusive. The given letters could be in any order and case, but the output should always be in all upper case, in alphabetical order.
  2. Draw a rectangle based on a given number of rows and columns, using a particular character for the display.
  3. Create a horizontal bar graph based on a set of positive integers. Use a character of your choosing to draw a bar (line) for each value, where the value tells you how many of the character to display.

A menu-driven program is one in which the user is presented with a list of choices, and must continue to pick a choice until they quit. For this program, each choice will correspond to an operation. Then the program will perform the operation, including getting any additional input that is needed. Here is a sample run to show you how each transaction is supposed to work. In the actual program, the user can choose the operations in any order, as many different times as s/he wants.

Please choose an operation:
0) quit
1) letters
2) rectangle
3) graph
choice -> 1

enter two letters: M b
B C D E F G H I J K L M


Please choose an operation:
0) quit
1) letters
2) rectangle
3) graph
choice -> 2

enter height, width & display character: 3 8 $
$$$$$$$$
$$$$$$$$
$$$$$$$$


Please choose an operation:
0) quit
1) letters
2) rectangle
3) graph
choice -> 3

enter all the numbers to process on one line: 23 14 4 20 8
***********************
**************
****
********************
********


Please choose an operation:
0) quit
1) letters
2) rectangle
3) graph
choice -> 0

BYE!

We will use the iterative development approach again. Try to finish all phases, but you do NOT have to stay beyond the scheduled 3 hours of lab! Remember to switch roles after each phase is completed.

Phase I: Write a program which repeatedly displays the transaction menu and reads an option from the user until they quit. Do not write the code to process any transactions yet, except to output one word indicating which operation was chosen.

--- Switch driver/nagivator roles ---

Phase II: Add to the program so that it correctly processes the first operation - the letters transaction. First get it to work if the characters are input in the correct order, in upper case. Then add processing to handle the cases where they are not both given in upper case, or in the correct order.

--- Switch driver/nagivator roles ---

Phase III: Add processing for the second operation - the rectangle transaction.

--- Switch driver/nagivator roles ---

Phase IV: Add processing for the third transaction type - bar graph. Hint: you can initialize a Scanner object with a String. Use this to get all the numbers on the line. First get this operation working so that it just prints the numbers, one per line. Then change it so that it prints a string of stars instead, where the number of stars corresponds to the value.

--- Switch driver/nagivator roles ---

Phase V: For an extra challenge, update the second operation so that it displays the outline of the rectangle, instead of a solid block of characters.

         **************************************************
   MAKE SURE YOU DELETE YOUR FILES OFF THE LAB COMPUTER WHEN DONE!!!
             FAILURE TO DO SO IS AN ETHICS VIOLATION!  
            (Save on a flash drive or in email first.)
         **************************************************