Numeric Data Types and Simple Input/Output

For these lab exercises, it is advised that you complete and test your program without using CodeLab first; and check your solution using CodeLab after you complete your solution.

Converting Celsius to Fahrenheit

Write a program that meets the following requirements:

  1. The program is called CelsiusToFahrenheit.java
  2. It tells the user what to do with a brief but meaningful prompt on the standard output. The prompt must be,
    Please enter a temperature in Celsius:
    
  3. It converts the temperature from Celsius to Fahrenheit. The formula to do that is as follows,

    where \(C\) is the temperature in Celsius, and \(F\) that in Fahrenheit

  4. It prints out the conversion result in a nice format on the standard output. The format is illustrated by the following example where the user enters 26 °C
    26.0 degrees Celsius is 78.8 degrees Fahrenheit.
    

Computing Cylinder Surface Area and Volume

Write a program that meets the following requirements:

  1. The program is called `CylinderCalculator.java’
  2. It reads in the radius and length of a cylinder from the standard input.
  3. It computes the surface area and the volume of the cylinder. The surface area of a cylinder is,

    where A is the surface area, V the volume, r the radius, and l is length

  4. It displays the area and the volume in a nice format illustrated by the example below,
    Enter the radius of the cylinder: 10
    Enter the length of the cylinder: 200
    The radius and the length of the cylinder are 10.0 and 200.0.
    The surface area of the cylinder is 13194.68914507713.
    The volume of the cylinder is 62831.853071795864. 
    

Displaying Fixed Number of Digits After Decimal Point

This is an extension to the previous exercises. The previous exercises do not have a requirement on displaying a given number of digits after the decimal point. In this exercise, you are to display only a fixed number of digits after the decimal point. Using the cylinder exercise as example, you are to complete the following program:

Write a program that meets the following requirements:

  1. The program is called `NiceCylinderCalculator.java’
  2. It reads in the radius and length of a cylinder from the standard input.
  3. It computes the surface area and the volume of the cylinder. The surface area of a cylinder is,

    where A is the surface area, V the volume, r the radius, and l is length

  4. It displays the area and the volume in a nice format where we print out at most 3 digits after the decimal points for the surface area and the volume. In this program, you are only allowed to use data type casting and numeric operations. Using Math.round() and/or Formatter is not allowed.
  5. The follow example illustrates the above requirements:

    Enter the radius of the cylinder: 10
    Enter the length of the cylinder: 200
    The radius and the length of the cylinder are 10.0 and 200.0.
    The surface area of the cylinder is 13194.689.
    The volume of the cylinder is 62831.853.