Projects |
|
|---|---|
Home Resources Essays Hobbies Hockey! Projects Resume |
04-14-02 Currently, I'm working on two major projects, the space strategy game, as yet, unnamed. Also, I'm slowly starting to get into real estate (though living in silicon valley, this promises to be expensive). I haven't actually bought anything yet, but I'm doing a lot of research...
7-28-01
Old ProjectsSenior Design Project (tspaces)Cabin Reservation calendar (finally done!) Coen 176 Lab 1 (qlist) Coen 176 Lab 1 (qarray) Lab 2 (shapes) Lab 4 Polygon Project fftInterface Lab 1 (Qlist.java)//------------------------------------ class Qlist.java ---------------------------------
/* Implements a queue as a linked list, with a maximum number of elements. 'First' is the
first element to be dequeued from the list, and last is the element at the end of the list.
*/
class Qlist {
public Qlist() {
first = null;
last = null;
}
public boolean full() {
return (size >= max_items);
}
public boolean empty() {
return (first == null);
}
public void enqueue(Object x) {
if (size < max_items) {
if (last == null) {
last = new QLnode(x);
first = last;
}
else {
last.SetNext(new QLnode(x));
last = last.GetNext();
}
size++;
}
else System.out.println("Queue overflow in class QList.");
}
public Object dequeue() {
Object ritem = null;
if (first == null) System.out.println("Queue underflow in class QList.");
else {
ritem = first.GetContents();
first = first.GetNext(); // in c++ we delete old node.
size--;
}
if (first == null) last = null;
return ritem;
}
private QLnode first, last;
private int size, max_items=100;
}
Lab 1 (Qarray.java)//------------------------------------ class Qarray.java ---------------------------------
/* class Qarray works by keeping track of the first item in the queue (oldest) and the size of
the Queue. If size+first is too large, the items will be inserted at the beginning of
the array.
*/
class Qarray
{
public boolean full() {
return (size >= max_items);
}
public boolean empty() {
return (size <= 0);
}
public void enqueue(Object x) {
int next = first+size;
if (next < max_items) {
items[next] = x;
size++;
}
else if (size < max_items) {
items[next-max_items] = x;
size++;
}
else System.out.println("Queue overflow in Qarray.");
}
public Object dequeue() {
Object ritem;
if (size > 0) {
ritem = items[first++];
if (first >= max_items) first -= max_items;
size--;
return ritem;
}
else {
System.out.println("Queue underflow in Qarray.");
return null;
}
}
private Object items[] = new Object[100];
private int first, size;
private int max_items = 100;
}
Lab 2 (shapes classes)package shapes;
public abstract class Shape {
public abstract double area();
public abstract double circumference();
}
package shapes;
public class Circle extends Shape {
protected double r;
protected static final double PI = 3.14159265358979323846;
public Circle() { r = 1.0; }
public Circle(double r) {this.r = r;}
public double area() { return PI * r * r;}
public double circumference() { return 2 * PI * r;}
public double GetRadius() {return r;}
}
package shapes;
public class Rectangle extends Shape {
protected double w,h;
public Rectangle() {w = 0.0; h = 0.0;}
public Rectangle(double w, double h) { this.w = w; this.h = h;}
public double area() { return w * h;}
public double circumference() { return 2 * (w+h);}
public double getWidth() {return w;}
public double getHeight() {return h;}
}
package shapes;
public class Square extends Rectangle {
public Square() {super();}
public Square(double w) {super(w,w);}
}
Lab 3import java.applet.*;
import java.awt.*;
public class Scribble extends Applet {
private int last_x = 0;
private int last_y = 0;
private Color current_color = Color.black;
private Button clear_button;
private Choice color_choices;
public void init() {
this.setBackground(Color.white);
clear_button = new Button("Clear");
clear_button.setForeground(Color.black);
clear_button.setBackground(Color.lightGray);
this.add(clear_button);
color_choices = new Choice();
color_choices.addItem("black");
color_choices.addItem("red");
color_choices.addItem("green");
color_choices.setForeground(Color.black);
color_choices.setBackground(Color.lightGray);
this.add(new Label("Color:"));
this.add(color_choices);
}
public boolean mouseDown(Event e, int x, int y) {
last_x = x;
last_y = y;
return true;
}
public boolean mouseDrag(Event e, int x, int y) {
Graphics g = this.getGraphics();
g.setColor(current_color);
g.drawLine(last_x, last_y, x, y);
last_x = x;
last_y = y;
return true;
}
public boolean action (Event event, Object arg) {
if (event.target == clear_button) {
Graphics g = this.getGraphics();
Rectangle r = this.bounds();
g.setColor(this.getBackground());
g.fillRect(r.x, r.y, r.width, r.height);
return true;
}
else if (event.target == color_choices) {
String colorname = (String) arg;
if (arg.equals("black")) current_color = Color.black;
else if (arg.equals("red")) current_color = Color.red;
else if (arg.equals("green")) current_color = Color.green;
return true;
}
else return super.action(event, arg);
}
}
|