Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

hi, can someone please help me with these, I just need an answere key to check m

ID: 3585851 • Letter: H

Question

hi, can someone please help me with these, I just need an answere key to check my answers so I can make sure I'm doing it right.

2)

(6Pts)

Write a class Wanderer that extends Critter. Each Wanderer is represented as a blue "W" and begins walking north. Each time a Wanderer encounters food it, with equal likelihood, either eats it and turns right or doesn’t eat it and continues walking in the same direction.

1) (8 Pts) What output is generated by the following code? Formatting counts, so be careful with it. public class Fire f public class Ice extends Fire t public void method1) C public String toString) [ return "Fire"; System.out.print("Ice 1 "); public void method1) method20; System.out.print ("Fire 1 "); public class Rain extends Fire [ public String toString) return "Rain"; public void method2) System.out.print("Fire 2 "); public void method1) f super.method1; System.out print ("Rain 1 "); public class Snow extends Rain public void method2) System.out print ("Snow 2 "); public class Mainf public static void main(String] args) f // init array with 4 objects Fire[] elements = {new Fire(), new Snow(), new Rain, new Ice) for (int i 0; i

Explanation / Answer

Proram 1: OUTPUT

Fire

Fire 2

Fire 1

Fire 2

Rain

Snow 2

Fire 1

Rain 1

Snow 2

Rain

Fire 2

Fire 1

Rain 1

Fire 2

Fire

Ice 1

Fire 2

Proram 3:

public class Echo {

String message;

int times;

/**

* @param message

*/

public Echo(String message) {

this.message = message;

times = 0;

}

public String multi(int n) {

String genMessage = "";

for (int i = 0; i < n; i++) {

genMessage += message;

}

times += n;

return genMessage;

}

@Override

public String toString() {

// TODO Auto-generated method stub

String genMessage = "";

for (int i = 0; i < times; i++) {

genMessage += message;

}

return "word: " + genMessage;

}

}

public class Main {

public static void main(String[] args) {

Echo e = new Echo("foo");

System.out.println(e.multi(2));

System.out.println(e.multi(3));

System.out.println(e);

}

}

OUTPUT

foofoo

foofoofoo

word: foofoofoofoofoo