TestJava.java Code
public class TestJava {
   private int count;

   public static double average(int i,int j,int k) {
      int sum = i+j+k;
      return sum/3;
   }
   public static int addSalesTax(int num) {
      int result = num*1.06;
      return result;
   }

   public static int multiply(int i,int j) {
      int result = i*j;
      return result;
   }

   public static void print(String s) {
      System.out.println(s);
   }

   public static int explicitMultiply(int a,int b) {
      int result = 0;
      while (b > 0) {
         result = result+a;
         b = b-1;
      }
      return result;
   }
}
Room.java Code
public class Room {

   private String name;
   private String description;
   private int charms;
   private Room northRoom;
   private Room southRoom;

   public Room(String n, String d) {
      name = n;
      description = d;
      charms = 0;
   }

   public String getName() { return name; }
   public String getDescription() { return description; }
   public int getCharms() { return charms; }

   public int alterCharms(int k) { charms = charms + k; }

   public Room getNorthRoom() { return northRoom; }
   public Room getSouthRoom() { return southRoom; }

   public void setNorthRoom(Room n) { northRoom = n; }
   public void setSouthRoom(Room s) { southRooom = s; }

}
AdventurePlayer.java Code
public class AdventurePlayer {

   private String name;
   private Room currentRoom;
   private int healthPoints;
   private int hitPoints;

   public AdventurePlayer(String n, Room c) {
      name = n;
      currentRoom = c;
      healthPoints = 0;
      hitPoints = 0;
   }

   public String getName() { return name; }
   public String getcurrentRoom() { return currentRoom; }
   public int getHealthPoints() { return healthPoints; }
   public int getHitPoints() { return hitPoints; }

   public void goNorth() { currentRoom = currentRoom.getNorthRoom(); }
   public void goSouth() { currentRoom = currentRoom.getSouthRoom(); }

}
Sample Interactions
Welcome to DrJava.
> Room bar = new Room("bar","a smokey bar");
> Room closet = new Room("closet","a broom closet");
> bar.setNorthRoom(closet);
> closet.setSouthRoom(bar);
> AdventurePlayer tim = new AdventurePlayer("tim",bar);
> tim.getName()
tim
> tim.getCurrentRoom().getDescription()
a smokey bar
> tim.goNorth()
> tim.getCurrentRoom().getDescription()
a broom closet
> tim.getHealthPoints()
0
Tutorials: Java and Programming | HTML and CSS | JavaScript | PHP | MySQL Copyright © 2007 Eric Fisher | A Production of eFishDesign