Introduction to Computer Science I

Lab 4


Program 1 -- Converting temperatures

Consider the following information about different metrics for temperatures:

Write a program, named ConvertTemperatures. This program must contain two methods, one for converting Fahrenheit to Celsius, and one for converting Celsius to Fahrenheit. Your program should do the following:

  1. Ask the user to enter a temperature in Fahrenheit.

  2. Convert that temperature to Celsius and show that conversion to the user.

  3. Take the Celsius value and convert it back to Fahrenheit, and show that value to the user as well. Is it exactly the same as what the user typed?


Program 2 -- Converting lengths

Now consider the following length information:

Armed with this information, write a program, named ConvertLengths, that can convert a measurement in any one of these three units into another. The program must contain one method for each possible conversion. Moreover, some of these methods should rely on others. In other words, don't calculate new conversions yourself; instead, write methods to perform the two conversions above, and then call on those methods to perform other conversions. For example, there's no information above on how to convert feet to smoots, but you could other methods to convert feet to meters, and then meters to smoots within the single method feetToSmoots.

Your interface with the user should look like this:

Enter the original metric: meters
Enter the converted metric: furlongs
Sorry, I only know feet, meters, and smoots.  Try again.
Enter the converted metric: smoots
Enter the length in meters: Montana
Please enter a numeric value.  Try again.
Enter the length in meters: 5.7
That's 3.3493947 smoots.
    

Note that you should also write methods to handle user input, checking that the input is valid.


Submitting your work

Submit your work like this:

cs11-submit lab-4 ConvertTemperatures.java ConvertLengths.java

This lab is due on Thursday, February 28th at 11:59 pm

Scott F. H. Kaplan
Last modified: Fri Mar 21 13:29:15 EDT 2008