AP CSA 2021 Q2 - CombinedTable Class
| <-- Back to Solution of Q1 (WordMatch) - FRQ - 2021 | Next to Solution of Q3 (ClubMembers) - FRQ - 2021 --> |
Solution of Q2 (CombinedTable) - Free Response Question - 2021
The original question can be found at: https://apcentral.collegeboard.org/media/pdf/ap21-frq-computer-science-a.pdf
Part (a)- public class CombinedTable{}
public class CombinedTable{
// each CombinedTable is formed by combining two tables
private SingleTable s1;
private SingleTable s2;
public CombinedTable(SingleTable st1, SingleTable st2)
{
s1= st1;
s2= st2;
}
public boolean canSeat(int seat)
{
int seat1= s1.getNumSeats();
int seat2 = s2.getNumSeats();
int newSeat = seat1 + seat2 -2;
if ( seat > newSeat) return false;
else return true;
}
public double getDesirability()
{
int h1= s1.getHeight();
int h2 = s2.getHeight();
double d=0.0;
if (h1 == h2)
d = (s1.getViewQuality() + s2.getViewQuality()) /2;
else d = ((s1.getViewQuality() + s2.getViewQuality()) /2 ) - 10;
return d;
}
}
Java project files (with Runner code):
| <-- Back to Solution of Q1 (WordMatch) - FRQ - 2021 | Next to Solution of Q3 (ClubMembers) - FRQ - 2021 --> |