Sprint View

2021 FRQ 2

8 min read

FRQ Question Part A

Assume SingleTable objects t1, t2, and t3 have been created as follows.

  • SingleTable t1 has 4 seats, a view quality of 60.0, and a height of 74 centimeters.
  • SingleTable t2 has 8 seats, a view quality of 70.0, and a height of 74 centimeters.
  • SingleTable t3 has 12 seats, a view quality of 75.0, and a height of 76 centimeters.

The chart contains a sample code execution sequence and the corresponding results.

Statement Value Returned (blank if no value) Class Specification
CombinedTable c1 = new CombinedTable(t1, t2);   A CombinedTable is composed of two SingleTable objects.
c1.canSeat(9); true Since its two single tables have a total of 12 seats, c1 can seat 10 or fewer people.
c1.canSeat(11); false c1 cannot seat 11 people.
c1.getDesirability(); 65.0 Because c1’s two single tables are the same height, its desirability is the average of 60.0 and 70.0.
CombinedTable c2 = new CombinedTable(t2, t3);   A CombinedTable is composed of two SingleTable objects.
c2.canSeat(18); true Since its two single tables have a total of 20 seats, c2 can seat 18 or fewer people.
c2.getDesirability(); 62.5 Because c2’s two single tables are not the same height, its desirability is 10 units less than the average of 70.0 and 75.0.
t2.setViewQuality(80);   Changing the view quality of one of the tables that makes up c2 changes the desirability of c2, as illustrated in the next line of the chart. Since setViewQuality is a SingleTable method, you do not need to write it.
c2.getDesirability(); 67.5 Because the view quality of t2 changed, the desirability of c2 has also changed.

The last line of the chart illustrates that when the characteristics of a SingleTable change, so do those of the CombinedTable that contains it.

Write the complete CombinedTable class. Your implementation must meet all specifications and conform to the examples shown in the preceding chart.

The class SingleTable represents a table at a restaurant.

(See in code block below)

At the restaurant, customers can sit at tables that are composed of two single tables pushed together. You will write a class CombinedTable to represent the result of combining two SingleTable objects, based on the following rules and the examples in the chart that follows.

  • A CombinedTable can seat a number of customers that is two fewer than the total number of seats in its two SingleTable objects (to account for seats lost when the tables are pushed together).
  • A CombinedTable has a desirability that depends on the views and heights of the two single tables. If the two single tables of a CombinedTable object are the same height, the desirability of the CombinedTable object is the average of the view qualities of the two single tables.
  • If the two single tables of a CombinedTable object are not the same height, the desirability of the CombinedTable object is 10 units less than the average of the view qualities of the two single tables.

// CODE_RUNNER: Class Creation

Code Runner Challenge

FRQ Example - CombinedTable / SingleTable

View IPYNB Source
// CODE_RUNNER: FRQ Example - CombinedTable / SingleTable
// Runnable example: includes a simple SingleTable implementation, CombinedTable, and Main to print results.

class SingleTable
{
    private int numSeats;
    private int height;
    private double viewQuality;

    public SingleTable(int numSeats, double viewQuality, int height)
    {
        this.numSeats = numSeats;
        this.viewQuality = viewQuality;
        this.height = height;
    }

    public int getNumSeats()
    {
        return numSeats;
    }

    public int getHeight()
    {
        return height;
    }

    public double getViewQuality()
    {
        return viewQuality;
    }

    public void setViewQuality(double value)
    {
        this.viewQuality = value;
    }
}

class CombinedTable
{
    private SingleTable table1;
    private SingleTable table2;

    public CombinedTable(SingleTable t1, SingleTable t2)
    {
        table1 = t1;
        table2 = t2;
    }

    public boolean canSeat(int n)
    {
        return (table1.getNumSeats() + table2.getNumSeats() - 2) >= n;
    }

    public double getDesirability()
    {
        double avg = (table1.getViewQuality() + table2.getViewQuality()) / 2.0;
        if (table1.getHeight() == table2.getHeight())
        {
            return avg;
        }
        else
        {
            return avg - 10.0;
        }
    }
}

public class Main
{
    public static void main(String[] args)
    {
        SingleTable t1 = new SingleTable(4, 60.0, 74);
        SingleTable t2 = new SingleTable(8, 70.0, 74);
        SingleTable t3 = new SingleTable(12, 75.0, 76);

        CombinedTable c1 = new CombinedTable(t1, t2);
        System.out.println("c1.canSeat(9): " + c1.canSeat(9));
        System.out.println("c1.canSeat(11): " + c1.canSeat(11));
        System.out.println("c1.getDesirability(): " + c1.getDesirability());

        CombinedTable c2 = new CombinedTable(t2, t3);
        System.out.println("c2.canSeat(18): " + c2.canSeat(18));
        System.out.println("c2.getDesirability(): " + c2.getDesirability());

        t2.setViewQuality(80.0);
        System.out.println("After t2.setViewQuality(80): c2.getDesirability(): " + c2.getDesirability());
    }
}
Main.main(null);
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Scoring Guidelines Part A

# Scoring Criteria Decision Rules Points
1 Declares class header: class CombinedTable and constructor header: CombinedTable(SingleTable ___, SingleTable ___) (must not be private) Responses can still earn the point even if they declare the class header as class CombinedTable extends SingleTable 1 point
2 Declares appropriate private instance variables including at least two SingleTable references Responses can still earn the point even if they declare an additional instance variable to cache the number of seats at the combined table. Responses will not earn the point if they: declare and initialize local variables in the constructor instead of instance variables; declare additional instance variable(s) that cache the desirability rating; omit keyword private; declare variables outside the class 1 point
3 Constructor initializes instance variables using parameters Responses can still earn the point even if they declare and initialize local variables in the constructor instead of instance variables 1 point
4 Declares header: public boolean canSeat(int ___)   1 point
5 Calls getNumSeats on a SingleTable object Responses can still earn the point even if they call getNumSeats on constructor parameters or local variables of type SingleTable in the constructor. Responses will not earn the point if they call the SingleTable accessor method on something other than a SingleTable object 1 point
6 canSeat(n) returns true if and only if sum of seats of two tables − 2 >= n Responses can still earn the point even if they call getNumSeats incorrectly 1 point
7 Declares header: public double getDesirability()   1 point
8 Calls getHeight and getViewQuality on SingleTable objects Responses can still earn the point even if they call getHeight or getViewQuality on constructor parameters or local variables of type SingleTable in the constructor 1 point
9 getDesirability computes average of constituent tables’ view desirabilities Responses can still earn the point even if they: call getHeight or getViewQuality on constructor parameters or local variables of type SingleTable in the constructor; fail to return the computed average (return is not assessed). Responses will not earn the point if they: fail to have an if statement and a correct calculation; choose the incorrect value (average vs. average − 10) based on evaluation of the if statement condition 1 point

Question-specific penalties: None

Total for question 2: 9 points


Applying the Scoring Criteria

Apply the question scoring criteria first, which always takes precedence. Penalty points can only be deducted in a part of the question that has earned credit via the question rubric. No part of a question (a, b, c) may have a negative point total. A given penalty can be assessed only once for a question, even if it occurs multiple times or in multiple parts of that question. A maximum of 3 penalty points may be assessed per question.

1-Point Penalty

  • v) Array/collection access confusion ([] get)
  • w) Extraneous code that causes side-effect (e.g., printing to output, incorrect precondition check)
  • x) Local variables used but none declared
  • y) Destruction of persistent data (e.g., changing value referenced by parameter)
  • z) Void method or constructor that returns a value

No Penalty

  • Extraneous code with no side-effect (e.g., valid precondition check, no-op)
  • Spelling/case discrepancies where there is no ambiguity*
  • Local variable not declared provided other variables are declared in some part
  • private or public qualifier on a local variable
  • Missing public qualifier on class or constructor header
  • Keyword used as an identifier
  • Common mathematical symbols used for operators (× ÷ <> )
  • [] vs. () vs. <>
  • = instead of == and vice versa
  • length/size confusion for array, String, List, or ArrayList; with or without ()
  • Extraneous [] when referencing entire array
  • [i,j] instead of [i][j]
  • Extraneous size in array declaration, e.g., int[size] nums = new int[size];
  • Missing ; where structure clearly conveys intent
  • Missing { } where indentation clearly conveys intent
  • Missing () on parameter-less method or constructor invocations
  • Missing () around if or while conditions

*Spelling and case discrepancies for identifiers fall under the “No Penalty” category only if the correction can be unambiguously inferred from context, for example, “ArayList” instead of “ArrayList”. As a counterexample, note that if the code declares "int G=99, g=0;", then uses "while (G < 10)" instead of "while (g < 10)", the context does not allow for the reader to assume the use of the lower case variable.

Course Timeline