This code gives me the following errors:
unreachable statement Line 99
missing return statement Line 135
JIFT.java
import java.util.*;
import java.applet.*;
import java.awt.*;
// JIFTDemo - Demonstrates some of the features of JIFT
// Last modification date : October 08, 1997
public class JIFT extends Applet {
Room currentLocation;
String command;
TextField commandInput;
TextArea displayOutput;
Button buttonInput;
// Constructor
public JIFT() {
super();
}
// Initialisation method
public void init() {
super.init();
// Define colours setBackground
setBackground(Color.white);
setForeground(Color.black);
Panel appletPanel = new Panel();
// Use a border layout
BorderLayout b = new BorderLayout();
appletPanel.setLayout (b); add(appletPanel);
// Define UI items
commandInput = new TextField(20);
displayOutput = new TextArea( 10, 60);
// 10 rows x 60 chars
buttonInput = new Button("Go");
Panel inputPanel = new Panel();
// Add components to our layout / panels
inputPanel.add(commandInput);
inputPanel.add(buttonInput);
appletPanel.add("North", displayOutput);
appletPanel.add("South", inputPanel);
// Create two locations
Room JailCell = new Room ("Jail Cell", "You stand at the entrance of your Jail Cell. Byond your cell you hear screaming in agony to the East. To The West is a hole large enough for you to fit through. The guards left your Cell door opened the last time your were served your meal");
Room Hall = new Room ("Hall", "You have reached the end of a long dark hallway. You see demons torturing inicent souls\n You decide its best to go back.");
Room SecretTunnel = new Room ("Secret Tunnel", "You move a large brick to find a secret tunnel leading out of your cell.\n You crawl through the tunnel to reach a small opening leading to the main Corridor");
// Create an exit for JailCell
JailCell.addExit (new Exit(Exit.NORTH, Hall));
JailCell.addExit (new Exit(Exit.EAST, SecretTunnel));
// Create an exit for Hall
Hall.addExit (new Exit(Exit.SOUTH, JailCell));
// Create an exit for SecretTunnel
SecretTunnel.addExit (new Exit(Exit.WEST, JailCell));
// Set up room locations
currentLocation = JailCell;
// Show first location
showLocation();
repaint();
}
private void showLocation() {
// Show room title
displayOutput.appendText( "\n" + currentLocation.getTitle() + "\n" );
displayOutput.appendText( "\n" );
// Show room description
displayOutput.appendText( currentLocation.getDescription() + "\n" );
// Show available exits
displayOutput.appendText( "\nAvailable exits : \n" );
for (Enumeration e = currentLocation.getExits().elements(); e.hasMoreElements();) {
Exit an_exit = (Exit) e.nextElement();
displayOutput.appendText (an_exit + "\n");
}
}
public boolean action (Event evt, Object focus) {
String command;
// Was a button pressed ?
if (evt.target instanceof Button) {
// Obtain string
command = commandInput.getText();
// Don't parse blank commands
if (command.length() == 0) {
return true;
// Convert to uppercase for comparison
command = command.toUpperCase();
// Search for an exit match
for (Enumeration e = currentLocation.getExits().elements(); e.hasMoreElements();) {
Exit an_exit = (Exit) e.nextElement();
if ( (an_exit.getDirectionName().compareTo(command) == 0) || (an_exit.getShortDirectionName().compareTo(command) == 0 ) ) {
// Set location to the location pointed to by exit
currentLocation = an_exit.getLeadsTo();
// Show new location
showLocation();
// Clear text area
commandInput.setText (new String());
// Event handled
return true;
}
}
// If code reaches here, direction is invalid
displayOutput.appendText ("\nHuh? Invalid direction!\n");
// Clear text area
commandInput.setText (new String());
// Event handled
return true;
}
// Event not handled else
return false;
}
}
}
Room.java
import java.util.Vector;
import java.util.Enumeration;
// Location - represents a gaming location //
// Last modification date : May 14, 2007
public class Room {
// Member variables
private String m_roomTitle;
private String m_roomDescription;
private Vector m_vecExits;
// Blank constructor
public Room() {
// Blank title + description
m_roomTitle = new String ();
m_roomDescription = new String();
m_vecExits = new Vector();
}
// Partial constructor
public Room( String title ) {
// Assign title
m_roomTitle = title;
// Blank description
m_roomDescription = new String();
// Blank exits
m_vecExits = new Vector();
}
// Full constructor
public Room( String title, String description ) {
// Assign title + description
m_roomTitle = title;
m_roomDescription = description;
// Blank exits
m_vecExits = new Vector();
}
// toString method
public String toString() {
return m_roomTitle;
}
// Adds an exit to this location
public void addExit ( Exit exit ) {
m_vecExits.addElement (exit);
}
// Removes an exit from this location
public void removeExit ( Exit exit ) {
if (m_vecExits.contains (exit)) {
m_vecExits.removeElement (exit);
}
}
// Returns a vector of exits
public Vector getExits () {
// Return a clone, as we don't want an external
// object to modify our original vector return (Vector)
m_vecExits.clone();
return (Vector) m_vecExits.clone();
}
// Returns location title
public String getTitle() {
return m_roomTitle;
}
// Assigns location title
public void setTitle( String roomTitle ) {
m_roomTitle = roomTitle;
}
// Returns location description
public String getDescription() {
return m_roomDescription;
}
// Assigns location description
public void setDescription( String roomDescription ) {
m_roomDescription = roomDescription;
}
}
Exit.java
// Exit - represents an exit to a location
// Last modification date : May 14, 2007
public class Exit {
// Numerical codes
public static final int UNDEFINED = 0;
public static final int NORTH = 1;
public static final int SOUTH = 2;
public static final int EAST = 3;
public static final int WEST = 4;
public static final int UP = 5;
public static final int DOWN = 6;
public static final int NORTHEAST = 7;
public static final int NORTHWEST = 8;
public static final int SOUTHEAST = 9;
public static final int SOUTHWEST = 10;
public static final int IN = 11;
public static final int OUT = 12;
// String codes
public static final String[] dirName = { "UNDEFINED", "NORTH", "SOUTH", "EAST", "WEST", "UP", "DOWN", "NORTHEAST", "NORTHWEST", "SOUTHEAST", "SOUTHWEST", "IN", "OUT" };
public static final String[] shortDirName = { "NULL", "N", "S", "E", "W", "U", "D", "NE", "NW", "SE", "SW", "I", "O" };
// Member variables
private Room m_leadsTo = null;
private int m_direction;
// Full name of direction eg SOUTHEAST
private String m_directionName;
// Shortened version of direction eg SE
private String m_shortDirectionName;
// Default constructor
public Exit() {
m_direction = Exit.UNDEFINED;
m_leadsTo = null;
m_directionName = dirName[UNDEFINED];
m_shortDirectionName = shortDirName[UNDEFINED];
}
// Full constructor
public Exit( int direction, Room leadsTo ) {
m_direction = direction;
// Assign direction names
if (direction <= dirName.length ){
m_directionName = dirName[m_direction];
}
if (direction <= shortDirName.length ){
m_shortDirectionName = shortDirName[m_direction];
}
// Assign location
m_leadsTo = leadsTo;
}
// toString method
public String toString() {
return m_directionName;
}
// Assigns direction name
public void setDirectionName( String dirname ) {
m_directionName = dirname;
}
// Returns direction name
public String getDirectionName() {
return m_directionName;
}
// Assigns short direction name
public void setShortDirectionName ( String shortName ) {
m_shortDirectionName = shortName;
}
// Returns short direction name
public String getShortDirectionName () {
return m_shortDirectionName;
}
// Assigns location
public void setLeadsTo ( Room leadsTo ) {
m_leadsTo = leadsTo;
}
// Returns location
public Room getLeadsTo ( ) {
return m_leadsTo;
}
}