Introduction To Programming
10-152-310

Learning Plan 2 : Variables and Data Types

The Issue

When our programs are very small, we can usually just write them. We don't really need to plan much. However, modern software can have hundreds of thousands of lines of code. Maybe some planning is appropriate? During this semester, as our programs get more and more complex, we're going to explore ways to think and plan out what to do.

Problem Statements

We will start working on our programs with a problem statement. These are a few paragraphs that describe the program that you will be writing. This is usually written by non-programmers and is intended to communicate to you, as best they can, what they want. Here are some examples.

Write a program that asks a user for 10 numbers. The program will then determine the smallest number, the largest number, and calculate the average of the number. The program will display the three calculated values.

Write a program that asks a user to enter the height of a child for each year of their life. The program will then determine which year the child grew the fastest and which year the child grew the slowest and output the calculated values.

Write a program that asks a user to enter a temperature in Fahrenheit and convert it to Celsius. The program will display the Fahrenheit temperature and the calculated Celsius temperature. A Celsius temperature is calculated by the formula 5 / 9 times Fahrenheit temperature minus 32.

Extracting the Nouns and Verbs

The first step in our planning is to look at the important words in problem statement. To which nouns and verbs do I have to pay attention? Here's how do to this with some of our examples. Here's the first one:

  • Write a program that asks a user for 10 numbers. The program will then determine the smallest number, the largest number, and calculate the average of the number. The program will display the three calculated values.

The important nouns have been highlighted:

  • Write a program that asks a user for 10 numbers. The program will then determine the smallest number, the largest number, and calculate the average of the number. The program will display the three calculated values.

The Nouns (and their adjectives)

  • 10 numbers
  • smallest number
  • largest number
  • average

The next thing we do is look at the important verbs.

  • Write a program that asks a user for 10 numbers. The program will then determine the smallest number, the largest number, and calculate the average of the number. The program will display the three calculated values.

The Verbs

  • ask
  • determine
  • calculate
  • display

Creating the Program Planning Lists

The next step is to take these nouns and verbs and make some checklists. This is a quick and fairly informal process. Don't get too hung up with being perfect or complete. We are trying to capture the high-level lists of key items in the program. The three lists we want to make are:

  • The list of input variables
  • The list of output variables
  • The checklist of processing steps

The List of Input Variables

Look at the nouns, which ones are inputs? Write those down as JavaScript variables.

Input Variables

  1. numberOne
  2. numberTwo
  3. numberThree
  4. numberFour
  5. numberFive
  6. numberSix
  7. numberSeven
  8. numberEight
  9. numberNine
  10. numberTen

The List of Output Variables

Next, look at the nouns for things that the program will need to output or display. Sometimes you will need to display the inputs. Sometimes you will need to display only the outputs. And sometimes a combination of both.

Output Variables

  1. smallestNumber
  2. largestNumber
  3. average

The Process Checklist

Here's where we start in on developing what our program actually does. This list will be very high-level, you don't need to have any detail! Look at the verbs. Do you see a pattern?

Those verbs are candidates for being on our list of steps. The first verb is "ask". What you are doing is getting input. That will be your first item on your list of steps you program is going to do. We're just going to convert it a little so it sounds more like we are programming it.

  • Prompt user for 10 numbers

Then next two verbs are "determine" and "calculate". This is the heart of the program. It's what the program is all about. The process step just has to say a little more.

  • Determine the smallest number
  • Determine the largest number
  • Calculate the average

The last verb is "display". This is the output step. Be brief!

  • Display smallestNumber, largestNumber, and average.

Now put them altogether.

Process Checklist

  • Prompt user for 10 numbers
  • Determine the smallest number
  • Determine the largest number
  • Calculate the average
  • Display smallestNumber, largestNumber, and average.

Read this to yourself, does it sound complete? Does is sound like a program? Now let's make it into a program!