Java
TOPIC 29 – FUNCTIONS 2

AP EXTRA – EXTRA PRACTICE

 

AP LESSON WORK

 

 

QUESTION 1 – HIT TEST

a) Create a simple class called Rectangle that has the following parameters:

·                         x – the x-coordinate of the top left point of the rectangle

·                         y – the y-coordinate for the top left point of the rectangle

·                         w – the width of the rectangle

·                         h – the height of the rectangle

 

b) You will now create another class called RectangleTester that will contain your main method.  Inside it, create two Rectangle objects named r1 and r2.

c) Still inside RectangleTester, you will create a function called overlap that gets two Rectangle objects as parameters and returns the boolean value true if the rectangles overlap each other, and false if they do not.

d) Back in main, test your overlap function to see if the rectangles you created in b actually overlap.  Change the values around to properly test your function.