Assignment No.2

  1. Write a class VariablePractice that performs conversions from acre to square feet, to square meters, and then to square yards through a series of assignments. The program should take the following actions:
    1. Declare four double variables acre, sqft, sqm, sqyd
    2. Assign a value, e.g., 1.0 to acre. This is the starting quantity.
    3. Assign the value of the formula acre * 43560 to sqft. This is the square feet value of the given acreage.
    4. Similarly, compute the square meter value of the given acreage by using a formula that multiplies the value of sqft by 0.3048 twice and storing the value to sqm. (This uses the fact that one foot in length is equal to 0.3048 meters.)
    5. Similarly, compute the square yard value of the given acreage by using a formula that divides the value of sqm by 0.9144 twice and storing the value to sqyd. (This uses the fact that one yard in length is equal to 0.9144 meters.)
    6. Then print the result in the following manner (the output example is based upon the value of 1.0 assigned to acre)

      1.0 acre is:
      43560.0 square feet,
      4046.8564224000006 square meters, and
      4840.000000000001 square yards.

      Note that each line can be produced by two statements: one System.out.print statement that prints the value of a variable and one System.out.println that prints the non-value part. For example, the first line can be generated using the following two statements:
      System.out.print( acre );
      System.out.println( " acre is:" );

  2. (Adapted from Textbook Chapter 2 Exercise 3) The Fibonacci numbers are the sequence of numbers, where the first two are both 1 and after that each number is the sum of the two numbers precedining immediatey to it. That is, the sequence is:

    1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...

    Write a class Fibonacci that prints the first five numbers, one number per line, as follows:
    1. Use int variables by the names of fOne, fTwo, fThree, fFour, fFive to store the first five numbers, respectively.
    2. Assign the value of 1 to fOne and fTwo
    3. Compute the values of the remaining three in order.
    4. Print the values of the five numbers, one per line.
    The output should look like:
    1
    1
    2
    3
    5

Go back to the assignment list page.