gt: 			    Matrix answer = temporaryMatrix1.scalarMultiply(constant);
context: /*
   * Main.java
   *
   * Created on December 8, 2003, 10:38 PM
   */
  
  /**
   *
   * @author  Joshua Gossett
   */
  
  /**
   * libraries
   */
  import java.io.*;
  import java.text.*;
  import java.util.Hashtable;
  
  public class Main {
  
      private static Hashtable variables;
  
      /** Creates a new instance of Main */
      public Main() {
      }
  
      //get the matrix inclosed in brakets
      public static Matrix getVariableTo(String commandLine){
  	String matrixName;
  	//searches for proper syntax
  	if(commandLine.indexOf("[") == -1 || commandLine.indexOf("]") == -1){
  	    System.out.println("ERROR --(main) missing a '[' or ']'.");
  	    return null;
  	}
  	else{
  	    //strips the brackets leave the matrix name
  	    matrixName = commandLine.substring(commandLine.indexOf("[")+1,
  					       commandLine.indexOf("]"));
  	    matrixName = matrixName.trim();
  	    Matrix returnMatrix = (Matrix)(variables.get(matrixName));
  	    if(returnMatrix == null){
  		System.out.println("ERROR --(main) \""+matrixName+"\" does not exist.");
  		return null;
  	    }else
  		return returnMatrix;
  	     
  	}
      }
  
      //gets the matrix before the sysmbol
      public static Matrix getVariableBefore(String commandLine,String sysmbol){
  	String matrixName ;
  	if(commandLine.indexOf("=") != -1)
  	     matrixName = commandLine.substring(commandLine.indexOf("=")+1,commandLine.indexOf(sysmbol));
  	else
  	    matrixName = commandLine.substring(0,commandLine.indexOf(sysmbol));
  	
  	matrixName = matrixName.trim();
  	
  	Matrix returnMatrix = (Matrix)(variables.get(matrixName));
  	if(returnMatrix == null){
  	    System.out.println("ERROR --(main) \""+matrixName+"\" does not exist.");
  	    return null;
  	}
  	else
  	    return returnMatrix;
      }
  
      //gets the matrix after the sysmbol
      public static Matrix getVariableAfter(String commandLine,String sysmbol){
  	String matrixName;
  
  	matrixName = commandLine.substring(commandLine.indexOf(sysmbol)+1,commandLine.length());
  	
  	matrixName = matrixName.trim();
  	
  	Matrix returnMatrix = (Matrix)(variables.get(matrixName));
  	if(returnMatrix == null){
  	    System.out.println("ERROR --(main) \""+matrixName+"\" does not exist.");
  	    return null;
  	}
  	else
  	    return returnMatrix;
      }
  
      //sets the matrix equal to the varible name after "="
      public static void setVariableTo(String commandLine,Matrix set){
  	String name;
  	//show the matrix
  	set.show();
  	//find where the '=' sign is
  	int i = commandLine.indexOf("=");
  	if( i != -1){
  	    //variable name = ever before equal sign
  	    name = commandLine.substring(0,i);
  	    name = name.trim();
  	    //place in hash table
  	    variables.put(name,set);
  	}
      }
  
      /**
       * @param args the command line arguments
       */
      public static void main(String[] args) {
          BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
          String commands = "quit";
          String matrix1;
          String matrix2;
  	Matrix temporaryMatrix1;
          Matrix temporaryMatrix2;
          variables = new Hashtable();
          do{
              System.out.print("Matrix Mania>> ");
              //get the commands for the prompt
              try{
                  commands = reader.readLine();
                  //ignore case
                  commands.trim();
                  commands = commands.toLowerCase();
                  //command calls
  
  		//create
  
                  if(commands.indexOf("matrix") != -1){
                      //Syntax error
                      if(commands.indexOf("[") == -1 || commands.indexOf("]") == -1){
                          System.out.println("ERROR --(main) missing a '[' or ']'.");
                      }
                      else{
                          
                          boolean errorFlag = false;
                          int rows = 0;
                          int columns = 0;
                          String matrix = commands.substring(commands.indexOf("["),
                                                             commands.indexOf("]"));
                          matrix.trim();
                          matrix = matrix.substring(3,matrix.length());
                          String[] elementRows = matrix.split("}");
                          rows = elementRows.length;
                          for(int i = 1; i < elementRows.length; i++){
                               elementRows[i] = elementRows[i].substring(2,elementRows[i].length());
                               elementRows[i] = elementRows[i].trim();
                          }
                          String[] elements = elementRows[0].split(",");
                          columns = elements.length;
                          double[] array = new double[columns*rows];
                          for(int i = 0; i < rows; i++){
                              elements = elementRows[i].split(","); 
                              if(columns != elements.length){
                                  System.out.println("ERROR --(main) rows are not the same size");
                                  errorFlag = true;
                                  break;
                              }
                              for(int k = 0; k < columns; k++){
                                  try{
                                      array[i*columns+k] = Double.parseDouble(elements[k]);
                                  }catch(NumberFormatException e){
                                      System.out.println("ERROR --(main) bad format.");
                                      errorFlag = true;
                                  }
                              }
                          }
                          if(errorFlag != true){
                              Matrix newMatrix = new Matrix(array,rows,columns);
                              newMatrix.show();
                              if(commands.indexOf("=") != -1){
                                  matrix1 = commands.substring(0,commands.indexOf("="));
                                  matrix1 = matrix1.trim();
                                  variables.put(matrix1,newMatrix);
                              }
                          }
                      }
                  }
  
  		//show or display
  		
                  else if(commands.indexOf("show") != -1){
  		    //get variable object
  		    temporaryMatrix1 = getVariableTo(commands);
  		    
  		    //check to see if it exist
  		    if(temporaryMatrix1 != null)
  			//show the matrix
  			temporaryMatrix1.show();   
                  }
  		
  		//determinate
  		
  		else if(commands.indexOf("det") != -1){
  		
  		    //get variable object
  		    temporaryMatrix1 = getVariableTo(commands);
  		    //check to see if it exist
  		    if(temporaryMatrix1 != null){
  			//show the matrix
  			double det = temporaryMatrix1.determinant();
  			System.out.println("    determinant = "+det);
  		    }   
                  }
  
  		//inverse
  		
  		else if(commands.indexOf("inverse") != -1){
  		    //get variable object
  		    temporaryMatrix1 = getVariableTo(commands);
  		    //check to see if it exist
  		    if(temporaryMatrix1 != null){
  			//show the matrix
  			Matrix inverse = temporaryMatrix1.inverse();
  			if(inverse != null)
  			    setVariableTo(commands,inverse);
  		    }  
                  }
  
  		//substration
  		
  		else if(commands.indexOf("-") != -1){
  		    temporaryMatrix1 = getVariableBefore(commands,"-");
  		    temporaryMatrix2 = getVariableAfter(commands,"-");
  
  		    if(temporaryMatrix2 != null && temporaryMatrix1 != null){
  			Matrix answer = temporaryMatrix1.substration(temporaryMatrix2);
  			if(answer != null)
  			    setVariableTo(commands,answer);
  		    }
  		}
  		
  		//additions
  		
  		else if(commands.indexOf("+") != -1){
  		    temporaryMatrix1 = getVariableBefore(commands,"+");
  		    temporaryMatrix2 = getVariableAfter(commands,"+");
  
  		    if(temporaryMatrix2 != null && temporaryMatrix1 != null){
  			Matrix answer = temporaryMatrix1.addition(temporaryMatrix2);
  			if(answer != null)
  			    setVariableTo(commands,answer);
  		    }
  		}
  
  
  		//scalar multiplication
  
  		else if(commands.indexOf("*") != -1){
  		    temporaryMatrix1 = getVariableAfter(commands,"*");
  
  		    if(temporaryMatrix1 != null){
  			String number;
  			if(commands.indexOf("=") != -1)
  			    number = commands.substring(commands.indexOf("=")+1,commands.indexOf("*"));
  			else
  			    number = commands.substring(0,commands.indexOf("*"));
  			try{
  			    double constant = Double.parseDouble(number);
  