Java

OOP GUIDE / WORK

 

SINGLETABLE CLASS

 

Topics

  • Inferring instance variables.
  • Implementing a constructor.
  • Implementing instance variables.

 

 

TASK – SINGLETABLE CLASS

 

We will create the SingleTable class which was a part of the 2021 AP exam (Free Response Question #2).  If you want to continue working with this class, you can look at the CombinedTable class example.

 

The SingleTable class represents a table in a restaurant.  Below, you can find the partial implementation for the class.

 

 

WORK

 

  1. Based on the method names, can you guess the instance variables for a SingleTable object?  Hint: There are three of them.

 

Answer
There are three get methods so that suggests there are (at least) three instance variables.  They are numberOfSeats, height and viewQuality.

 

  1. Create the SingleTable class in Eclipse and include:

·       Instance variables,

·       A constructor,

·       Instance method implementations

  1. In a class called TableTester, add a main function and create the following three SingleTable objects: