# Table

* `int numSeats`: the number of seats at this table. Always greater than or equal to 4.
* `int height`: height of the table in centimeters.
* `double viewQuality`: quality of the view from this table.&#x20;

**The complete SingleTable class has been provided.  You must use it to complete Hackathon.**&#x20;

```java
public 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 viewQuality) {
        this.viewQuality = viewQuality;
    }
}
```

<mark style="background-color:orange;">At the restaurant, customers can sit at tables that are composed of two single tables pushed together.</mark> 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.

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.

<table data-header-hidden><thead><tr><th width="279.3333333333333">Statement</th><th width="98">Value Returned (blank if no value)</th><th>Class Specification</th></tr></thead><tbody><tr><td>CombinedTable c1 = new   CombinedTable(t1, t2);</td><td> </td><td>A CombinedTable is composed of two SingleTable objects.</td></tr><tr><td>c1.canSeat(9);</td><td>true</td><td>Since its two single tables have a total of 12 seats, c1 can seat 10 or fewer people.</td></tr><tr><td>c1.canSeat(11);</td><td>false</td><td>c1 cannot seat 11 people.</td></tr><tr><td>c1.getDesirability();</td><td>65.0</td><td>Because c1's two single tables are the same height, its desirability is the average of 60.0 and 70.0.</td></tr><tr><td>CombinedTable c2 = new   CombinedTable(t2, t3);</td><td> </td><td>A CombinedTable is composed of two SingleTable objects.</td></tr><tr><td>c2.canSeat(18);</td><td>true</td><td>Since its two single tables have a total of 20 seats, c2 can seat 18 or fewer people.</td></tr><tr><td>c2.getDesirability();</td><td>62.5</td><td>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.</td></tr><tr><td>t2.setViewQuality(80);</td><td> </td><td>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.</td></tr><tr><td>c2.getDesirability();</td><td>67.5</td><td>Because the view quality of t2 changed, the desirability of c2 has also changed.</td></tr></tbody></table>

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.&#x20;

Test the code based on the table above. You should pass the the test in order to receive full credit.&#x20;

### Full Score:

Ding Chengtian

Zhang Tianyu

Dai Weide

Dong Ruoxuan

Lin Jiaxin

Wang Jiaxi

Zhang Wenyuan

Zhu Qixin

Zhu Yi

### Almost There:

Liu Xintong

Cao Qizhen

Hu Yuqin

Luo Rui

Lv Jiajia

Zheng Hao


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://scls-cs.gitbook.io/apcs-lab/apcsa-i-2023-fall/di-shi-wu-zhou/table.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
