Java
TOPIC 37 – CONSTRUCTORS II
AP EXTRA
AP LESSON WORK
QUESTION 1
Consider the Book class from the previous AP lesson. Let's pretend it will now be used inside of
a video game as a randomly generated item.
You need to add a constructor that has
no parameters. It randomly generates
an author, title and year. Be
creative.
QUESTION 2
Create a Line class. It will represent
a line object. Its data fields are two
Point objects. So you will need the
Point class in your project.
You need the following constructors:
Constructor #1 gets a Point object as
parameter for each data field.
Constructor #2 gets four double values representing x1, y1 and x2, y2. You need to create the Point objects inside
the constructor.
Constructor #3 gests no
parameters. It creates a line from (0,0) to (100,100).
Test your Line class and each constructor.
|