Spirograph Problem Set Javadocs

spirograph
Class SpiroUtils

java.lang.Object
  extended byspirograph.SpiroUtils

public abstract class SpiroUtils
extends java.lang.Object

This class contained a bunch of Utilities that were specific to this problem set, but only one of them turned out to be neccesary.

Copyright © 1998 Massachusetts Institute of Technology
Copyright © 2003 Franklin W. Olin College of Engineering

Version:
$Id: SpiroUtils.java,v 1.6 2004/02/09 20:55:03 gus Exp $
Author:
Luis Sarmenta, lfgs@cag.lcs.mit.edu, Henry Wong, henryw@mit.edu, Patrick G. Heck, gus.heck@olin.edu
See Also:
Accelerator

Field Summary
static java.lang.String[] RESERVED_WORDS
          The reserved words for java 1.4.
 
Constructor Summary
SpiroUtils()
           
 
Method Summary
static Accelerator createAccel(java.lang.String className)
          This method reads in a class file, creates an Object from that class and casts it to an Accelerator.
static double dist(double ax, double ay, double bx, double by)
          The distance between any two points in 2D space.
static boolean inEllipse(double x, double y, double a, double b)
          Calculates whether or not a given position is inside a given ellipse.
static boolean isReservedWord(java.lang.String someCode)
          Check to see if a string contains a java reserved word.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESERVED_WORDS

public static final java.lang.String[] RESERVED_WORDS
The reserved words for java 1.4. Altough the student's shouldn't ever use assert in this lab, I have included it for completeness. If you are using an SDK earlier than 1.4 and a student picks a variable named assert, this will cause problems, but this should be acceptably rare.

Constructor Detail

SpiroUtils

public SpiroUtils()
Method Detail

isReservedWord

public static boolean isReservedWord(java.lang.String someCode)
Check to see if a string contains a java reserved word.

Parameters:
someCode - The code or other string to check for reserved words
Returns:
true if a reserved word is detected, false otherwise

createAccel

public static Accelerator createAccel(java.lang.String className)
This method reads in a class file, creates an Object from that class and casts it to an Accelerator.

Class.forName(String) caches names, if I ask it to reread a file that the user has changed it will return the old version of that file. Therefore, I use some system calls to copy the file to a new name, read it in and erase it.

This method is only used to load the classes, if any, specified as command line arguments when the program is started. It is not used to load the classes that are compiled during the execution of the program. To do this, a cs101.util.MultiClassLoader is used.

Parameters:
className - The string specifying the name of the class to load
Returns:
The loaded class if it implements Accelerator, null otherwise.

dist

public static double dist(double ax,
                          double ay,
                          double bx,
                          double by)
The distance between any two points in 2D space.

Parameters:
ax - first x coordinate
ay - first y coordinate
bx - second x coordinate
by - second y coordinate
Returns:
the distance between the (ax,ay) and (bx,by)

inEllipse

public static boolean inEllipse(double x,
                                double y,
                                double a,
                                double b)
Calculates whether or not a given position is inside a given ellipse. The elipse is assumed to be centered on 0,0 with major and minor axes coinciding with the x and y coordinate axes.

Parameters:
x - The x coordinate of the point being tested
y - The y coordinate of the point being tested
a - The major or minor axis of the elipse in the x direction
b - The major or minor axis of the elipse in the y direction
Returns:
true if the point is in the elipse false otherwise

Spirograph Problem Set Javadocs