HERE IS THE PAD CLASS..PLEASE USE THE PAD TESTER BELOW IT TO COMPLETE THIS /** *
ID: 3568490 • Letter: H
Question
HERE IS THE PAD CLASS..PLEASE USE THE PAD TESTER BELOW IT TO COMPLETE THIS
/**
* The Pad class is used to represent individual lily pads in the
* pond. Each pad keeps track of its starting status and it's
* status as the the game goes on (VACANT, FROG, TOAD, or INVALID
* - these are public symbolic constants that will also be used in
* other classes). Among other things, each Pad object needs to be
* capable of determining whether or not it is in the solved-puzzle
* configuration (ignoring all the other lily pads).
*/
public class Pad
{
/** Symbolic constant representing a lilypad with a frog */
public static final int FROG = 1;
// add the remaining 3 constants WITH JAVADOCS descriptors
// INSTANCE VARIABLES
private int currentState; // the current state of lilypad
private int startState; // The original state of lilypad
/**
* Creates a new lily pad with a given initial state (the state
* when the game begins).
* @param startState - the starting state of the lilypad (FROG, TOAD, VACANT or INVALID)
*/
public Pad(int startState)
{
// initialise instance variables
this.currentState = startState;
this.startState = startState;
}
/**
* Returns the current state of the lily pad; either VACANT, TOAD, FROG, or INVALID.
*
* @return the currentState
*/
public int getStatus()
{
return currentState;
}
/**
* Returns true if this lily pad is in the correct state for the solved puzzle and
* false otherwise.
*/
public boolean isSolved()
{ // use the following algorithm:
// if the startState is FROG and the current state is TOAD return true
// else if the startState is TOAD and the current state is FROG return true
// else if the startState is VACANT and the current state is VACANT return true
// otherwise ...
return false;
}
/**
* copy the javadocs here for the reset method, then write the method
*/
/**
* copy the javadocs here for the setStatus method, then write the method
*/
/**
* Returns the string representation of the lily pad.
*/
public String toString()
{
if (currentState == FROG)
return "F";
// add symbols for the other possibilities
else // must be INVALID
return "#";
}
}
PAD TESTER
/**
* Test app for the Pad class, verifies proper operation of a pad object
*
* @author (your name)
* @version (a version number or a date)
*/
public class PadTester
{
public static void main(String [] args){
Pad p = new Pad( Pad.FROG );
System.out.println("The current status of Pad p = " + p.getStatus() );
System.out.println("Pad p = " + p ); // invokes p.toString()
System.out.println("Is p solved? " + p.isSolved() ); // should say false
// TEST CASE 1 FROG start, TOAD finish
p.setStatus(Pad.TOAD);
System.out.println("Pad p = " + p ); // should say T
System.out.println("Is p solved? " + p.isSolved() ); // should say true
p.reset();
System.out.println("Pad p = " + p ); // should say F
System.out.println("Is p solved? " + p.isSolved() ); // should say false
// TEST CASE 2 TOAD start, FROG finish
Pad p2 = new Pad(Pad.TOAD);
System.out.println("Pad p2 = " + p2 ); // should say T
p2.setStatus(Pad.VACANT);
System.out.println("Pad p2 = " + p2 ); // should say O
System.out.println("Is p2 solved? " + p2.isSolved() ); // should say false
p2.setStatus(Pad.FROG);
System.out.println("Pad p2 = " + p2 ); // should say F
System.out.println("Is p2 solved? " + p2.isSolved() ); // should say true
p2.reset();
System.out.println("Pad p2 = " + p2 ); // should say T
System.out.println("Is p solved? " + p2.isSolved() ); // should say false
// TEST CASE 3 VACANT start, VACANT finish
// add your test statements here
// create a Pad VACANT. Test toStrin, isSolved and setStatus methods.
}
}
Explanation / Answer
http://euclid.nmu.edu/~mkowalcz/cs120f08/projects/frogsAndToads/
i think the above link helps you
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.