Write a critter class Tigger along with its movement and eating behavior. All un
ID: 3530773 • Letter: W
Question
Write a critter classTiggeralong with its movement and eating behavior. All unspecified aspects ofTiggeruse the default behavior. Write the complete class with any fields, constructors, etc. necessary to implement the behavior.
Bouncing is what Tiggers do best! TheTigger's movement is to bounce up and down to increasingly large heights. ATiggerobject is passed an integer when it is constructed that represents his initial bounce height. (You may assume that this bounce height is at least 1.) Whatever bounce height is passed, he will move that many steps NORTH, then that many steps SOUTH, then repeat for a bounce height 1 larger. For example, anew Tigger(4)will move NORTH 4 times, then SOUTH 4 times, then NORTH 5 times, then SOUTH 5 times, then NORTH 6 times, then SOUTH 6 times, and so on.
When aTiggerfinds food, he eats it and completely starts over his bouncing behavior. That is, he starts over going NORTH on a bounce whose height is equal to the initial bounce height with which theTiggerwas constructed. For example, the following would be a sequence of moves for anew Tigger(2). Notice how he starts over every time he eats:
Explanation / Answer
what is the output you are expecting from this.
Are you expecting N,N, S,S, N,N,N, S,S,S, N,N,N,N, S,S,S,S, N(eats food),N,N, S,S, N,N,N, S,S,S, N,N,N,N,if 2 is passed?
However i writing to get the above output.
--------------------------------------------------------------
package movie;
import java.util.Scanner;
public class Tiggeralong {
String north;
String south;
int bounceHeight;
public Tiggeralong(int bounceHeight) {
super();
this.bounceHeight = bounceHeight;
}
public void moveSouth()
{
System.out.println("S");
}
public void moveNorth()
{
System.out.println("N");
}
public static void main(String[] args)
{
Scanner scan=new Scanner(System.in);
Tiggeralong t=new Tiggeralong(1);
Tiggeralong temp=t;
boolean eat=false;
String eating;
while(!eat)
{
for(int i=0;i<t.bounceHeight;i++)
{
t.moveNorth();
}
for(int i=0;i<t.bounceHeight;i++)
{
t.moveSouth();
}
t.bounceHeight++;
System.out.println("wanna eat ? y/n");
eating=scan.nextLine();
if(eating.equals("y"))
{
t.bounceHeight=temp.bounceHeight;
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.