The Hole Class Description:
For the Hole class, there are three instance variables: the parfor the hole, the length of the hole in yards, and a Boolean valuedindicator of whether the hole is one in which the players’ fulldrives will be measured for distance. John clarifies: The length ofthe hole in yards determines par for the hole. The current standardis:
No more than 250 yards | Par 3 |
251 to 470 yards | Par 4 |
471 to 690 yards | Par 5 |
Greater than 690 yards | Par 6 |
The distance of drives will only be counted as “full†on holesat least 400 yards long. Both the Hole constructor and a setLengthmethod use the length of the hole to calculate the par for the holeand determine whether full drives on the hole will be measured.There are “getters†for the length and the par of the hole and anisFullDriveHole method that returns true if and only if the hole isone where drives are measured.
The Hole Class:
public class Hole
{
// instance variables
private int par;
private int lengthInYds;
private boolean fullDriveHole;
 Â
/**
* Constructor for objects of class Hole.
*
* @param length of hole in yards
*
**/
public Hole(int length)
{
this.setLength(length);
}
 Â
/**
* Set the length of the hole and compute its par.
*
* @param length the length in of the hole in yards.
*/
public void setLength(int length)
{
// constants for determining par
final int par3Limit = 250;
 Â
     // GUIDE: add constants for limitsfor par 4 and par 5
   // GUIDE: set the length of the hole, initializethe instance variable
     // GUIDE: Write an IF-ELSE for asequence of comparisons to
     // GUIDE:  assign parbased on the length of the hole
     // GUIDE: Be sure to use theconstants you defined above
 Â
// determine if this a driving hole
     // GUIDE: Write code to properlyassign a value to this.fullDriveHole
}
 Â
/**
* get the length of the hole.
*
* @return int the length of the hole in yards.
*/
public int getLength()
{
return this.lengthInYds;
}
 Â
/**
* get the par of the hole.
*
* @return int par for the hole.
*/
public int getPar()
{
return this.par;
}
 Â
/**
* determine if drives are measured on this hole.
*
* @return boolean true iff drives in the fairway aremeasured.
*/
public boolean isFullDriveHole()
{
return this.fullDriveHole;
}
}
The Hole Class TestCase:
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class HoleTest
{
/**
* Default constructor for test class HoleTest.
*/
public HoleTest()
{
// not used in this Lab
}
/**
* Test the constructor.
*/
@Test
public void testConstructor()
{
// Create a Hole instance
// GUIDE: Replace this and next line with your code
assertTrue(false);
 Â
// Test to see if the instance was created
// GUIDE: Replace this and next line with your code
assertTrue(false);
 Â
// Test the instance variables have been initializedcorrectly.
// Note - these tests assumes the get methods are correct.
// GUIDE: Replace this and next line with your code
assertTrue(false);
}
 Â
/**
* Test the setLength method.
*/
@Test
public void testSetLength()
{
// Create a Hole instance
Hole hole1 = new Hole(250);
 Â
// Change the length of the hole
//hole1.setLength(249);
 Â
// Test the impact of changing the length to one of a par 3hole
assertEquals(249, hole1.getLength());
assertEquals(3, hole1.getPar());
assertFalse(hole1.isFullDriveHole());
 Â
// Add a test for a par 4 that will be measured
 Â
// GUIDE: Replace this and next line with your code
hole1.setLength(460);
 Â
assertEquals(460, hole1.getLength());
assertEquals(3, hole1.getPar());
assertFalse(hole1.isFullDriveHole());
 Â
// Add a test for par 5
// GUIDE: Replace this and next line with your code
hole1.setLength(475);
 Â
assertEquals(475, hole1.getLength());
assertEquals(5, hole1.getPar());
assertFalse(hole1.isFullDriveHole());
 Â
// Add a test for par 6
// GUIDE: Replace this and next line with your code
hole1.setLength(695);
 Â
assertEquals(695, hole1.getLength());
assertEquals(6, hole1.getPar());
assertFalse(hole1.isFullDriveHole()); Â Â
}
}