My Code:

public 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() {
        if (table1.getHeight() == table2.getHeight()) {
            return (table1.getViewQuality() + table2.getViewQuality()) / 2;
        } else {
            return (table1.getViewQuality() + table2.getViewQuality()) / 2 - 5;  
        }
    }
}

I used GPT to score mine (gave it the rubric and question)

image

8/9 (Gpt counted wrong)

What I should Improve on:

  • reading the questions more carefully
  • adding comments in code so i can easily understand while doing it
  • use access modifiers for clarity and consistency

Corrected Code

public class CombinedTable {
    private SingleTable table1;
    private SingleTable table2;

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

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

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

What I corrected

  • fixed the incorrect penalty in getDesirability
  • added this. to clarify instance variable assignment
  • Ensured proper constrctor access modifier