IPO Charts

Things To Do First

Things To Do Later

IPO

So far, we've written programs that display output on the console. If we needed data in our program, we typed it in the source code. It is more likely that most of your inputs will come from other source, such as a file or from the user. You'll work with files in the next Java course, but in this course we can look at a few different ways to get user input.

IPO Structure

The basic foundation of any program is the IPO structure. IPO stands for Input-Processing-Output:

Example:

A program calculates the area of a room. Possible inputs, processing, and outputs might be:

IPO Charts

An IPO Chart is one of several tools that programmers use when designing a program (before coding it!). An IPO chart has areas for Input, Processing, and Output, and allows you to plan out what your program needs to do.

When completing an IPO chart for a program, you actually do it in this order:

  1. Output: What is the goal of the program, what information should it produce? Why do we do this first? If you were going away on a trip, first you'd have to decide where you were going! So when designing a program, first you have to decide what it's supposed to do, what it needs to produce or show the user.
  2. Inputs: Next, decide what inputs you need in order to produce the desired output(s). What piece(s) of data are needed?
  3. Processing: We do this last, once we know the outputs and the inputs needed to determine those outputs. Here is where we decide how we create each output by transforming the input data. Typically we'd write a note about how each output is obtained.

Example

Inputslength of room
width of room
Processingarea = length * width
Outputsarea of the room

Exercises

1. Define the inputs, processing, and outputs for a program that gives the surface area and volume of a cylinder. (hint: http://math.about.com/library/blmeasurement.htm or http://www.1728.com/diamform.htm)

2. Define the inputs, processing, and outputs for a program that displays the future value of an investment for a principal P at a rate R compounded yearly for n years. The formula for compound interest is final amount = P(1+R/100)n.

[solutions]

Exercises

The following exercises will help us put together everything we've learned so far about writing Java programs.

For each of the programming questions below, draw up an IPO chart outlining the inputs, processing, and outputs each program solution requires.

  1. Develop a solution for a program that converts a temperature from Fahrenheit to Celsius. (Celsius temperature = 5.0/9.0 * (Fahrenheit temperature - 32.0).
  2. Develop a solution for a program that calculates a person's target heart rate (a target heart rate is the heart rate you should aim to maintain while you're working out). Use the following formula: Target Heart Rate = .7 * (220 - your age) + .3 * Resting Heart Rate (your resting heart rate is your heart rate while you're not participating in any physical activity).
  3. Write a tip calculator that allows a restaurant or bar customer to calculate the amount of a tip to give their wait person. The program should allow the customer to specify the bill amount and the percentage of tip they would like to give.
  4. The three ingredients required to make a bucket of popcorn in a movie theatre are popcorn, butter, and a bucket. Write a program that requests the cost of these three items and the price of a serving of popcorn (assume we have only one size). The program should then display the profit.
  5. You would like to be able to calculate your average grade for all the courses you've taken in first semester. Write a program that prompts you for the grades for the five courses you would have completed in first term. After recording all five grades, display the average grade on the console.

    Sample output using sample data:

    You entered your five grades as:  85.6 78.9 75.5 90.0 86.5
    Your average grade:  83.3

[solutions]