Java

REVIEW TOPIC 05 – FUNCTIONS

 

LESSON WORK

 

 

QUESTION 1A


In a class called Areas, implement the following functions:

 

public static double rectangleArea(double w, double l)

 

Simply returns the area of a rectangle of width w and length l.

 

public static double squareArea(double s)

 

Simply returns a function call to the rectangleArea function with appropriate parameters to calculate the area of a square with sidelength s.

 

public static double parallelogramArea(double w, double h)

 

Again, this uses the rectangleArea function to calculate the area of the parallelogram specified by width w and height h.

 

public static double circleArea(double r)

 

Returns the area of the circle specified by radius r.

QUESTION 1B

 

Write the code that uses the functions from 1A to answer the question below.  And yes that bottom shape is a parallelogram.


 

QUESTION 2

 

In a class called PoolAreas, implement the following functions:

 

public static double roundPool(double r)

 

This function uses the circleArea function from the previous question to return an answer.

 

public static double rectangularPool(double w, double l)

 

This function returns the area of this shape of pool using functions from the previous question.

 

public static double pillPool(double h, double maxLength)

 

Again, this function uses the previous class’ functions to calculate the specified pool.  Note that for such a pool, the ends are half circle with a diameter equal to the height.

 

 

public static double fortyFivePool(double w, double l)

 

Note that this pool has 45 degree angles in the corners.  These sections are always 4 feet by 4 feet no matter what size the rest of the pool is.

 

 

QUESTION 3

 

Prepare a test program that allows the user to specify the pool type and the program returns the area of the pool.

 

Sample output

 

What type of pool do you have?

 

1-Round pool

2-Rectangular pool

3-Pill pool

4-Forty Five pool

3

 

What is the height?

12

 

What is the max length?

32

 

The area of the pool is 353.094 square feet.

 

QUESTION 4

 

Add functionality for pool volume.  Test your functions but no need to create a detailed program like in Question 3.