The Hole Class Description: For the Hole class, there are three instance variables: the par for the...

60.1K

Verified Solution

Question

Programming

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

Answer & Explanation Solved by verified expert
4.3 Ratings (547 Votes)
Here is the completed code for both classes Commentsare included go through it learn how things work and let me knowif you have any doubts or if you need anything to change If youare    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students