Class cw3d

java.lang.Object
  extended by cw3d

public class cw3d
extends java.lang.Object

Author: Joanne Louise Carter
Date: 02/01/05
Module: G6DICP Introduction to Computer Programming
Title: ICP Coursework 3
SCSiT Username: jxc04m
This program implements the entire TPL specification. If an error is found then an appropriate error message is printed and the program ends - you must correct the error(s) to have the program run to completion.


Constructor Summary
cw3d()
           
 
Method Summary
static int getInt(java.util.Vector<TPLvariable> tplData, java.lang.String varORint, int lineCounter)
          This method is to aid in calculations.
static void main(java.lang.String[] args)
          The main method.
static int searchVector(java.util.Vector<TPLvariable> tplData, java.lang.String var)
          This method searches through the tplData Vector to find a specific variable.
static int str2int(java.lang.String str2convert)
          This method converts a string to an integer.
static int variableType(java.util.Vector<TPLvariable> tplData, int index)
          This method takes the variable from the Vector at the specified index and returns the data type (INTEGER or STRING) of the variable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

cw3d

public cw3d()
Method Detail

searchVector

public static int searchVector(java.util.Vector<TPLvariable> tplData,
                               java.lang.String var)
This method searches through the tplData Vector to find a specific variable.

Parameters:
tplData - Contains the TPL variables, can be searched through. TPLvariable is the type of object that can be put into the Vector.
var - String containing the variable name to be searched for.
Returns:
The index of the variable which is being searched for. Else, it returns -1 if the variable does not exist.

variableType

public static int variableType(java.util.Vector<TPLvariable> tplData,
                               int index)
This method takes the variable from the Vector at the specified index and returns the data type (INTEGER or STRING) of the variable.

Parameters:
tplData - Contains the TPL variables, can be searched through. TPLvariable is the type of object that can be put into the Vector.
index - The position of the variable in the Vector.
Returns:
The data type of the variable, for casting.

str2int

public static int str2int(java.lang.String str2convert)
This method converts a string to an integer. .valueOf returns an Integer - we call its .intValue to return an int.

Parameters:
str2convert - The String that is to be converted to an integer.
Returns:
An integer, or -9999 if there is an error. The error message could go in the try statement, but this method works better for the code.

getInt

public static int getInt(java.util.Vector<TPLvariable> tplData,
                         java.lang.String varORint,
                         int lineCounter)
This method is to aid in calculations. It takes the argument supplied, checks if it is a variable and returns the data in that variable, if it is not a variable then it tries to convert it to an int, if this fails too then it throws an error.

Parameters:
tplData - Contains the TPL variables, can be searched through. TPLvariable is the type of object that can be put into the Vector.
varORint - The String from the CALCULATE statement, which is either a variable name or an integer.
lineCounter - Counts the number of lines processed, shows where the error is.
Returns:
An integer for calculation, or an error (and exit).

main

public static void main(java.lang.String[] args)
The main method. Puts it all together and outputs the interpreted file.