cover picture cover picture


Homework 2

CMP 167: Programming Methods I
Lehman College, City University of New York
Spring 2016


This Homework Is Due By 11:59 PM on Wednesday February 24, 2016

  1. In your textbook, this homework problem is in section 2.20 Homework 2-1.

    Write a program that asks the user for three integers (firstInt, secondInt, thirdInt), perform the following operations and output the results:

    1. Add firstInt and secondInt then divide the result by thirdInt
    2. Multiply secondInt by thirdInt and divide result by the sum of secondInt and firstInt
    3. Multiply firstIntY by thirdInt and find the remainder of dividing the result by secondInt

    Your prompt to the user to enter the integers must be:

    	Enter firstInt: 
    	Enter secondtInt: 
    	Enter thirdInt: 
          

    Your output must be of the format:

    	First result = firstResult 
    	Second result = secondResult 
    	Third result = thirdResult 
          

    Please note that your class should be named IntegerExpressions.

  2. In your textbook, this homework problem is in section 2.21 Homework 2-2.

    Write a program that asks the user for time in days and prints the number of years and days (assume that there are 365 days in a year). Note that you should use "years" and "days" for all outputs (even in the cases where it is grammatically incorrect).

    For example:

    	If the user entered: 367, your program would output: 1 years and 2 days.
    	If the user entered: 750, your program would output: 2 years and 20 days
    	If the user entered, 1000, your program would output, 2 years and 270 days.
          

    Your prompt to the user to enter the number of days must be:

    	Enter number of days:
          

    Your output must be of the format:

    	numYears years and numDays days. 
          

    Please note that your class should be named YearsAndDays.

  3. In your textbook, this homework problem is in section 2.22 Homework 2-3.

    Write a program that prompts the user for a double value representing a radius. You will use the radius to calculate:

    	Circumference of a circle with that radius (circleCircumference = 2π r)
    	Area of a circle with that radius (circleArea = π r2)
    	Area of a sphere with that radius (sphereArea = 4π r2)
    	Volume of a sphere with that radius (sphereVolume = 43π r3)
    
    	You may assume that π = 3.1415926
          

    Your prompt to the user to enter the number of days must be:

    	Enter radius:
          

    Your output must be of the format:

    	Circle Circumference = circleCircumference
    	Circle Area = circleArea
    	Sphere Area = sphereArea
    	Sphere Volume = sphereVolume
          

    Please note that your class should be named CircleSphere.

Please submit the completed assignment in the corresponding section(s) in your textbook Lehman College City University of New York CMP 167 Spring 2016: Programming in Java. No other forms of submission will be accepted.