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
}
}
Wednesday, April 6, 2011
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
- Create new project called Point.
- Change program file name to Point.
- Change class declaration to Point instead of main.
- Right-click the Point file and select Reverse Engineer.
- Create new class diagram.
- Drag and drop the class option to the window.
- Change class name from Untitled to Point.
- Change the main method to public int manhattanDistance(Point other)
- 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
- Create a new project called Rectangle.
- Change the java file name to Rectangle.
- Change the class declaration to Rectangle.
- Right-click the java file and select Reverse Engineer.
- Create a new class diagram for the Rectangle class.
- Drag and drop the class option to the window.
- Change the class name from Untitled to Rectangle.
- Change the main method to public Rectangle(int x, int y, int width, int height)
- Add the attributes int x, int y, int width, int height.
- 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
- Create new project called RationalNumber.
- Change file name from Main.java to RationalNumber.java.
- Change class declaration from Main to RationalNumber.
- Right-click the RationalNumber.java file and select Reverse Engineer.
- Create a new class diagram of RationalNumber.
- Drag and drop the class option to the window.
- Change the class name from Untitled to RationalNumber
- Change the main method to public RationalNumber(int numerator, int denominator).
- Add the attributes int numerator and int denominator.
- 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
Subscribe to:
Comments (Atom)