Java

OOP GUIDE / WORK

 

COMBINEDTABLE CLASS SOLUTIONS

 

Source

  • This question was part of the 2021 AP exam free response questions.  A link to all past AP exam free response questions is available on the index page.

 

 

TASK – PART 1 – SETUP - SINGLETABLE CLASS

 

No solution required.

 

 

TASK – PART 2 – CREATING THE COMBINEDTABLE CLASS

 

Here is my solution:

 

 

public class CombinedTable

{

     private SingleTable t1;

     private SingleTable t2;

    

     public CombinedTable(SingleTable ta, SingleTable tb)

     {

           t1 = ta;

           t2 = tb;

     }

    

     public boolean canSeat(int desiredSeats)

     {

           if (desiredSeats <= t1.getNumSeats() + t2.getNumSeats() - 2)

                return true;

           else

                return false;

     }

    

     public double getDesirability()

     {

           if (t1.getHeight() == t2.getHeight())

                return (t1.getViewQuality() + t2.getViewQuality()) / 2;

           else

                return (t1.getViewQuality() + t2.getViewQuality()) / 2 - 10;

     }

}

 

 

 

TASK – PART 3 – TESTING THE COMBINEDTABLE CLASS

 

No solution required.