Java Tutorial Lesson 05: Method arguments

From Erlands Wiki

Jump to: navigation, search

You have a “Game” class that looks as follows:

public class Game {
    public static void main(String[] args) {
        System.out.println("Lesson 5");
        System.out.println();
        Room room = new Room(1);
        room.print();
    }
}

Your job is to create the Room class.

When starting the program with:

java Game

It should give the output:

Lesson 5
 
----------
|        |
|    1   |
|        |
----------

Some optional things to try:

  1. Try change the main class so a random number is printed in the box instead of the hardcoded 1
  2. Try to update the Room class so it looks good even if the number is more than one digit
  3. Try to update the Room class and Game class so it can write a custom text string instead of a digit


Personal tools