public class SingleTable
{
private int numSeats;
private double viewQual;
private int height;
public SingleTable( int ns, double vq, int h )
{
numSeats = ns;
viewQual = vq;
height = h;
}
public int getNumSeats()
{
return numSeats;
}
public int getHeight()
{
return height;
}
public double getViewQuality()
{
return viewQual;
}
public void setViewQuality( double vq )
{
viewQual = vq;
}
}
|
public class CombinedTable
{
private SingleTable t1, t2;
public CombinedTable(SingleTable a, SingleTable b)
{
t1 = a;
t2 = b;
}
public boolean canSeat(int numPeople)
{
// Write this method for part A
return false; // Statement added to prevent compile error
// Remove it when you write this method
}
public double getDesirability()
{
// Write this method for part B
return 0; // Statement added to prevent compile error
// Remove it when you write this method
}
}
|
Use this Java program to test your answer to question A:
public class TestA
{
public static void main(String[] args)
{
SingleTable t1 = new SingleTable( 4, 60, 74);
SingleTable t2 = new SingleTable( 8, 70, 74);
SingleTable t3 = new SingleTable(12, 75, 76);
CombinedTable c1 = new CombinedTable(t1, t2);
System.out.println( c1.canSeat( 9) ); // true
System.out.println( c1.canSeat( 10) ); // true
System.out.println( c1.canSeat( 11 )); // false
CombinedTable c2 = new CombinedTable(t2, t3);
System.out.println( c2.canSeat( 18 ) ); // true
System.out.println( c2.canSeat( 19 ) ); // false
}
}
|
The correct answers are given in the comments inside the test program.
Use this Java program to test your answer to question B:
public class TestB
{
public static void main(String[] args)
{
SingleTable t1 = new SingleTable( 4, 60, 74);
SingleTable t2 = new SingleTable( 8, 70, 74);
SingleTable t3 = new SingleTable(12, 75, 76);
CombinedTable c1 = new CombinedTable(t1, t2);
System.out.println( c1.getDesirability() ); // 65.0
CombinedTable c2 = new CombinedTable(t2, t3);
System.out.println( c2.getDesirability() ); // 62.5
t2.setViewQuality(80);
System.out.println( c2.getDesirability() ); // 67.5
}
}
|
The correct answers are given in the comments inside the test program.