Wednesday, April 6, 2011

centipede

BOARD : 
package centipede;

//import java.awt.event.KeyEvent;
//import java.awt.event.KeyListener;

import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.WindowConstants;


public class Board extends JFrame{

  private JTextArea Board;
  private int height = 50;


  private int width = 50;

  public Board(int height, int width) {
    Board = new JTextArea();

    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    Board.setColumns(width + 1);
    Board.setRows(height);
    Board.setEditable(false);
    Board.setFont(new java.awt.Font("Monospaced", 0, 12));
    Board.setLineWrap(true);
    Board.setAutoscrolls(false);
//    Board.addKeyListener(this);

    setTitle("Centipede Game");
    add(Board);

    pack();
    setResizable(false);
  }
    public JTextArea getBoard() {
    return Board;
  }


}





CENTIPEDE : 
 package centipede;



public class Centipede {


    private char segment = '@';

    private int length = 5;


    private int speed;
    private Board board;


    public Centipede (Board board) {
      this.board = board;
    }


    public void move () {
      int edge = board.getWidth();
    }


    public int getLength () {
        return length;
    }

    public void setLength (int val) {
        this.length = val;
    }


    public char getSegment () {
        return segment;
    }

    public void setSegment (char val) {
        this.segment = val;
        char[] centipede = new char[length];
        for (int i = 1; i <= length; i++) {
          centipede[i] = segment;
        }
    }



    public void hit () {
    }

      public int getSpeed () {
        return speed;
    }


    public void setSpeed (int val) {
        this.speed = val;
    }

}









MAIN: 
 
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package centipede;

import javax.swing.JTextArea;

/**
 *
 * @author student
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
      //nothing here yet
    }

}

Tuesday, April 5, 2011

homework 9 documentation


Homework 9








Kaitlyn Monteer
MU ID: 005553861
5 April 2011

E8.1

Design document

Class
Purpose
Point
Container for program.

Program diagram

Developments steps

  1. Create new project called Point.
  2. Change program file name to Point.
  3. Change class declaration to Point instead of main.
  4. Right-click the Point file and select Reverse Engineer.
  5. Create new class diagram.
  6. Drag and drop the class option to the window.
  7. Change class name from Untitled to Point.
  8. Change the main method to public int manhattanDistance(Point other)
  9. Save the diagram and drag and drop it to the Point file.

Test results

Step
Expected Output
Actual Output
1
None
None
2
None
None
3
None
None
4
None
None
5
None
None
6
None
None
7
None
None
8
None
None
9
None
None

E8.13

Design document

Class
Purpose
Rectangle
Container for program.

Program diagram


Developments steps

  1. Create a new project called Rectangle.
  2. Change the java file name to Rectangle.
  3. Change the class declaration to Rectangle.
  4. Right-click the java file and select Reverse Engineer.
  5. Create a new class diagram for the Rectangle class.
  6. Drag and drop the class option to the window.
  7. Change the class name from Untitled to Rectangle.
  8. Change the main method to public Rectangle(int x, int y, int width, int height)
  9. Add the attributes int x, int y, int width, int height.
  10. Add the method public String toString().

Test results

Step
Expected Output
Actual Output
1
None
None
2
None
None
3
None
None
4
None
None
5
None
None
6
None
None
7
None
None
8
None
None
9
None
None
10
None
None

 



P8.1

Design document

Class
Purpose
RationalNumber
Container for program.

Program diagram

Developments steps

  1. Create new project called RationalNumber.
  2. Change file name from Main.java to RationalNumber.java.
  3. Change class declaration from Main to RationalNumber.
  4. Right-click the RationalNumber.java file and select Reverse Engineer.
  5. Create a new class diagram of RationalNumber.
  6. Drag and drop the class option to the window.
  7. Change the class name from Untitled to RationalNumber
  8. Change the main method to public RationalNumber(int numerator, int denominator).
  9. Add the attributes int numerator and int denominator.
  10. Add the method public String toString().

Test results

Step
Expected Output
Actual Output
1
None
None
2
None
None
3
None
None
4
None
None
5
None
None
6
None
None
7
None
None
8
None
None
9
None
None
10
None
None


References

Sun Microsystems. (2004). Scanner (Java 2 Platform SE 5.0). Sun Microsystems, Inc., Santa Clara, CA USA. [Online]. Available http://java.sun.com/j2se/1.5.0/docs/api/java/util/Scanner.html