CSCI 201: Intro to Programming (Java)

Assignment 2.    Due: Mon, Oct 2

Please put your work in directory cs201 on your Linux account before 11:59pm of the day above.

  1. (25 points)   Write a Java application that reads three integers entered by the user by using the keyboard and outputs the maximum and the minimum numbers.

    Name the project Hw2_1
    Solution

  2. (25 points)   Write an application that asks the user for a year and replies either "Leap Year" or "Not Leap Year" accordingly. It is a leap year if the year is divisible by 4 but not by 100 (e.g., 1976 is a leap year). A year that is divisible by both 4 and 100 is a leap year if it is also divisible by 400 (e.g., 2000 is a leap year but 1800 is not).

    Name the project Hw2_2
    Solution

  3. (25 points)   Write an application that converts centimeters to feet and inches (1 in = 2.54 cm). Implement this application by using an instantiable class Conversion whose instance is capable of converting metric measurements to U.S. units and vice versa. Some of the public methods are
    public static double toFeet(double centimeters)
    public static double toInches(double centimeters)
    public static double toCentimeter(int feet, int inches)
    public static double toCentimeter(double yard)
    Your design should consist of two classes, one of which is the class Conversion specified above. The other class Hw2_3 should contain method main that asks the user to enter a floating point value (or, resp. two integers), apply to it the methods of class Conversion, and output the results to the screen with 3 decimal places.

    Put both classes in project Hw2_3
    Solution

  4. (25 points)   Write an application that computes the area and circumference of a circular region (the shaded area in the diagram) given the radius of the inner and the outer circles.

    The area can be computed by subtracting the area of the inner circle from the area of the outer circle. The circumference is the sum of the corresponding values for the inner and outer circles. If the outer radius is smaller that the inner one, the area and circumference should be 0. You can use constant Math.PI in computations.

    Define an instantiable class Circle that stores the radii as class variables and has methods to compute the area and circumference. You set the circle radii with the setRadii method.

    Your project should consist of two classes: Circle and Hw2_4. The second class has to contain method main which asks the user to enter the radii and outputs the area and the circumference.

    Put both classes in project Hw2_4
    Solution