Monday, May 19, 2008

Java Simple Programs: Problem #1

Write a Java program that prints the following as output:

Java is so
different
from Alice!

(Rules: You can only use ONE System.out.println statement).

Sunday, May 11, 2008

Tut 4 - Supplementary - Problem #2


Problem #2: Given a scenario with a princess and a dragon.


  • Write a class-level method, called shakeHead, for dragon to shake his head. This method must have a Number parameter. If the number parameter has the value 1, then the dragon shakes his head up and down (i.e. meaning yes).Else, if the number parameter has another value, then the dragon shakes his right to left (i.e. meaning no).


  • Next, make the princess ask the dragon some questions:

    • Are you a guy dragon? Dragon replies by shaking his head yes.

    • Did you kill the wizard? Dragon replies by shaking his head yes.

    • Are you gonna eat me lor? Dragon replies by shaking his head no.


Tut 4 - Supplementary Problem #1


Problem #1: Given a scenario with 2 sharks and 2 fish.


  • (a) Write a world-level method, called sharkEat1, that
    checks the following: If shark is near to the fish within 3 meters, shark moves toward the fish and eats it. If not, shark turns around and moves away 2 meters.


  • (b) Write a world-level method, called sharkEat2, that checks the following:
    If shark2 is near to the goldfish within 3 meters, shark2 moves toward the goldfish and eats it. If not, shark2 turns around and moves away 2 meters.



Call both methods from my first world method.

Monday, May 5, 2008

Tutorial 3 - Supplementary - Problem 2


Problem 2: Given a scenario with a castle, girl, wizard, and dragon where the Dragon is attacking the Castle. You finish the scenario where the dragon attacks the wizard, wizard fights back, and kills the dragon.
You have to create the following methods:

  • (a) A class-level method for dragon, called MoveNFlap, that moves the dragon forward 4 meters and flaps its wings at the same tiem. Then, call this method 2 times from my first world method.

  • (b) A class-level method for dragon, called CircleObject, to circle around any object (i.e. a parameter). Then, call this method from my first world method to circle around the wizard. (Hint: use asSeenby)

  • (c) A class-level method for wizard, called Teleport, to allow the wizard to teleport to behind the dragon. This means, turn to face dragon, become invisible, move to behind the dragon, and become visible again. Then, call this method from my first world method.

  • (d)) A world-level method, called KillDragon, where the wizard says his magic words again and the dragon disappears.

Sunday, May 4, 2008

Tutorial 3 - Supplementary - Problem 1


Problem 1: Pass It On!
You are given randomGuy2, skaterGirl, and aliceLiddell standing.
Create using methods and parameters a way for randomGuy2 to pass the
message he says ("hurray") to skaterGirl, who then passes it to Alice.
When skaterGirl receives the message, she should say it and pass it on to Alice.
When Alice receives the message she should say it.

(Rules: You need to create exactly two new methods: GuyPassToGirl and GirlPassToGirl
Each method must pass a parameter, which is the message.)