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.

The complete SingleTable class has been provided. You must use it to complete Hackathon.

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;
    }
}

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.

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.

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.

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

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

Last updated