Java
TOPIC 36 – CONSTRUCTORS

AP EXTRA

 

AP LESSON WORK

 

 

QUESTION 1

Create a class that will define Book objects.  The data fields are:

 

·         String title

·         String author

·         int year


Create a constructor that gets a value for each of the data fields.

 

Finally, in a BookTester class, create three different books of your choice.  For example, you could create On The Origin of Species by Charles Darwin (1859). 


QUESTION 2

Create a class called Triangle.  Its data fields are three Point objects.  To do this, you will have to create a Point class (or copy one from another lesson).

 

You are to include a constructor that gets an object for each of the data fields.

 

Inside a main method, create three Point objects.  Then use those Point objects to create a Triangle object. 

 

Output the coordinates of the points inside the Triangle object. 

 

Extra – After doing everything above, try changing on of your Point objects.  Now output your Triangle object's coordinates.  This is a concern that we will have to deal with in the future.