Assignment 3: Converting and averaging temperatures

The goal of this assignment is to produce a program using the software development process we have learned in class and to write a program that interacts with the user.

1. Setup

As last time, move into your cs241 directory. Make a directory for this assignment, and change into it.

> cd cs241
> mkdir assign3
> cd assign3

Open a file called TempConvert.java in Xemacs.

> xemacs TempConvert.java &

2. Specification

You are to write a program which will convert temperature readings from Fahrenheit to Celsius and calculate an average temperature. Here's the program's specification:

The program should prompt the user for five temperatures in Fahrenheit, and then display each of the temperatures in Celsius and an average temperature, in Celsius. The inputed temperature should be integers, but the output must be real numbers.

A run of the program should look something like this:

Please enter a temperature in Fahrenheit--> 72
Please enter a temperature in Fahrenheit--> 32
Please enter a temperature in Fahrenheit--> 0
Please enter a temperature in Fahrenheit--> 100
Please enter a temperature in Fahrenheit--> 212
72 converts to 22.22222222222222
32 converts to 0.0
0 converts to -17.77777777777778
100 converts to 37.77777777777778
212 converts to 100.0
Average temp: 28.444444444444446

3. The process

Practice the development process we learned in class Friday. Think through the specification, and then figure out an algorithm to solve it. Once you think you know what to do, write the documentation heading, and write a program that implements your algorithm. Then work through the compiler errors (don't be discouraged if you get errors-- because you certainly will get them!) and test the program until you're sure it works, documenting as you go along.

4. Technical hints

The formula for converting from Fahrenheit to Celsius is

       DegreesCelsius = 5 * (DegreesFahrenheit - 32) / 9

Remember, to prompt the user and read in an integer, use DocsIO.readint("...").

5. Style and documentation

Follow the style and documentation principles we've talked about in class-- document each variable declaration, variables should be in lowercase (unless you use internal capitalization to separate words), etc. Use Xemacs's tabbing feature to make the lines aligned nicely. See the course style principles for a review and example; only the first six rules apply to us so far.

6. Turn in

Turn in the same way you did last time. Here are the instructions again:

  1. When you are all finished and are confident that your program fulfills all the instructions here and is working right, start the script program, giving it a file name like "assign3script".
       > script assign2script
    
  2. Remove the ".class" file. That's what the compiler makes, and you want to show you are compiling from scratch.
        > rm *.class
    
  3. Display your code. Do this using the cat command.
        > cat TempConvert.java
    
  4. Compile your program.
       > javac TempConvert.java
    
  5. Run your program.
       > java TempConvert
    
  6. Exit the script.
       > exit
    
  7. Mail your script file to the class homework account.
    1. Go to your home directory
         > cd
      

      and start the mail program "pine."

         > pine
      
    2. Log into pine.
    3. Compose a new message by pressing "C". Enter "homework.cs241@wheaton.edu" as the address in the "to" field.
    4. In the body of the message, press "Ctrl-R" to read in a file. When you are asked for the file name, give "cs241/assign3/assign3script" or whatever you have called your script file.
    5. Send the message using "Ctrl-X".

You can exit pine by pressing "Q" for "quit".

DUE: Friday, Jan 28, at 5:00 PM.


Thomas VanDrunen
Last modified: Wed Jan 26 18:49:57 CST 2005