Skip to main content
Lesson 7 - More About Methods
ZIPPDF (letter)
Lesson MenuPreviousNext
  
L.A.7.1 - Fun page 8 of 10

Assignment:

  1. The two temperature scales used in the United States are Celsius and Fahrenheit. The mathematical relationship between the two scales is:

    Write two methods, fToC and cToF, which convert temperatures from one scale to another. For example, a call of fToC will return the equivalent Celsius temperature for a given Fahrenheit temperature.

    Celsius = fToC(100);	 // Celsius now stores 37.8
  2. Write a method that takes in the radius of a sphere and returns its volume. The formula is:

    You are encouraged to use a constant for the value of

  3. Write a method that returns the hypotenuse of a right triangle given the input of the two smaller sides. Use the Pythagorean theorem:

Instructions:

  1. Format all floating point values to two decimal places (0.01).

  2. You can use the following format of an output statement to test your program:

    System.out.println("212 F --> " + Format.left(fToC(212), 10, 2));

    the main method could be written using only 11 method calls.

  3. Use the following values to test your functions:

    Fahrenheit to Celsius: 212°F, 98.6°F, 10°F
    Celsius to Fahrenheit: -15°C, 0°C, 70°C
    Volume of a sphere, radius of: 1.0, 2.25, 7.50
    Hypotenuse calculations: sides of 3.0 and 4.0, sides of 6.75 and 12.31

Lesson MenuPreviousNext
Contact
 ©ICT 2003, All Rights Reserved.