Java

TOPIC 12D – TEST III REVIEW

 

 

DETAILS & REVIEW

 

 

DETAILS

 

The test covers the OOP unit of the grade 11 course as well as this OOP unit from grade 12.  All notes.  All work.

 

Your test will be fully written.  You will not have a computer.

 

Minor programming errors will not count against you.

 

 

REVIEW


QUESTION 1
You should be aware of the meaning of the following terms:

 

class
object (or instance)

instance variable (or data field)
instance method
constructor

default constructor
data encapsulation

aggregation

method overloading

private

public

get method

set method
null
null pointer exception

this

constructor chaining

toString()


QUESTION 2 – SHORT ANSWER QUESTIONS

Look over the short answer questions and solutions from the OOP Exercises.

 

QUESTION 3 – PRISM CLASS IMPLEMENTATION

 

Do the Prism class from the OOP Exercises.

 

QUESTION 4 – PEN CLASS IMPLEMENTATION

 

Do the Pen class from the OOP Exercises.

 

QUESTION 5 – DATA ENCAPSULATION


Consider the following class:

     public class Person

     {

        public String firstName;

        public String lastName;

        public int birthYear;

 

        public Person(String f, String l, int by)

        {

           firstName = f;

           lastName = l;

           birthYear = by;

        }

     }

 

5.1-Change the class so that it has full data encapsulation.  (Make the datafields private.)

 

5.2-Add get methods for all datafields.

 

5.3-Add set methods for all three datafields.  The names could be set to anything. However, the birth year only gets set if the birth year is above 1900 and below the current year.

 

4.4-Include a method called ageAtEndOf(int year) that returns the Person’s age at the end of the year year.

QUESTION 5 – OOP ARRAY

 

Do the Point class 2 from the OOP Exercises.

 

QUESTION 6 – AGGREGATION

 

Create a Page class that has three instance variables: pageNumber, header and content.  Create an appropriate constructor.  Create an appropriate toString() method.

 

Test your Page class.

 

Create a Book class that contains an array of Page objects.  Its constructor gets a book title, an author and an array of content and creates the Page[] with the Book title at the top of even pages and the Author’s name at the top of odd pages.

 

There is also a method called getPage() that gets a page based on its number. 

 

Create an appropriate toString() method.

 

Test your Book class out.

 

 

Good luck!