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

Wednesday, March 30, 2011

P7.1

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

package p71;

import java.util.Scanner;

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

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


        Scanner scanner = new Scanner(System.in);
        System.out.print("How many digits in the BIGGER number? (must be 50 or less): ");
        int n = scanner.nextInt();


        double[] num1 = new double[n];

        double[] num2 = new double[n];

        System.out.println("Enter the digits from SMALLEST to LARGEST.\nDigits must be between 0 and 99.");

        int i;
        for (i = 0; i < n; i++) {
          Scanner in = new Scanner(System.in);
          System.out.print("Enter a digit: ");
          num1[i] = in.nextDouble();
        }

        System.out.println("Now enter the digits in the SMALLER NUMBER from SMALLEST to LARGEST. \nUse the same number of digits as the larger number; \nEnter 0 if the value of that digit is zero.\n(Ex. Larger number: 5004, Smaller number: 312. \nEnter 2, 1, 3, 0 for the smaller number.) ");

        int j;
        for (j = 0; j < n; j++) {
          Scanner in = new Scanner(System.in);
          System.out.print("Enter a number in the array: ");
          num2[i] = in.nextDouble();
        }

        double[] sum = new double[n];

        int k;
        for (k=1; k <= n; k++) {
          sum[k] = num1[k] + num2[k];
        }

        System.out.println("Sum = " + sum + "\n(Ex. if sum = [1, 13, 0, 0, 1],\nthen the sum is 23,001.)");


    }

}

E7.8

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

package e78;

import java.util.Arrays;
import java.util.Scanner;

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

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("How many numbers in the array?: ");
        int n = scanner.nextInt();

        double[] array = new double[n];

        int i;
        for (i = 0; i < n; i++) {
          Scanner in = new Scanner(System.in);
          System.out.print("Enter a number in the array: ");
          array[i] = in.nextDouble();
        }

        Arrays.sort(array);
       
        int middle = array.length/2; 

     
        System.out.println("Median = " + array[middle]);



    
    }


}

E7.2

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

package e72;

import java.util.Scanner;

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

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

        arrayRange();   



    }

    public static void arrayRange() {
     
        Scanner scanner = new Scanner(System.in);
        System.out.print("How many numbers in the array?: ");
        int n = scanner.nextInt();


        double[] array = new double[n];


        int i;
        for (i = 0; i < n; i++) {
          Scanner in = new Scanner(System.in);
          System.out.print("Enter a number in the array: ");
          array[i] = in.nextDouble();
        }


        double maximum = array[0];   // start with the first value
        for (int j=1; j<n; j++) {
          if (array[j] > maximum) {
            maximum = array[j];   // new maximum
            }
        }


        double minimum = array[0];
        for (int k=1; k<n; k++) {
          if (array[k] < minimum) {
            minimum = array[k];
          }
        }


        double range = maximum - minimum;
        System.out.println("Range = " + range);
}
}

Tuesday, February 22, 2011

/*
 * File:   main.c
 * Author: student
 *
 * Created on February 21, 2011, 9:47 PM
 */

#include <stdio.h>
#include <stdlib.h>

/*
 *
 */
int main(int argc, char** argv, int num1) {
    printf("Enter the exponent of 10: ");
    scanf("%d",&num1);
    int  number = num1;
    if (number == 1) {
        printf("ten\n");
    }
    else {
    if (number == 2) {
        printf("one hundred\n");
    }
    else {
    if (number == 3) {
        printf("one thousand\n");
    }
    else {
    if (number == 4) {
        printf("ten thousand\n");
    }
    else {
    if (number == 5) {
        printf("one hundred thousand\n");
    }
    else {
    if (number == 6) {
        printf("one million\n");
    }
    else {
    if (number == 7) {
        printf("en million\n");
        }
    else {
    if (number == 8) {
        printf("one hundred million\n");
    }
    else {
    if (number == 9) {
        printf("one billion\n");
    }
    else {
    if (number == 10) {
        printf("ten billion\n");
    }
    else {
    if (number == 11) {
        printf("one hundred billion\n");
    }
    else {
    if (number == 12) {
        printf("one trillion\n");
    }
    else {
    if (number == 13) {
        printf("ten trillion\n");
    }
    else {
    if (number == 14) {
        printf("one hundred trillion\n");
    }
    else {
    if (number == 15) {
        printf("one quadrillion\n");
    }
    else {
    if (number == 16) {
        printf("ten quadrillion\n");
    }
    else {
    if (number == 17) {
        printf("one hundred quadrillion\n");
    }
    else {
    if (number == 18) {
        printf("one quintillion\n");
    }
    else {
    if (number == 19) {
        printf("ten quintillion\n");
    }
    else {
    if (number == 20) {
        printf("one hundred quintillion\n");
    }
    else {
    if (number == 21) {
        printf("one sextillion\n");
    }
    else {
    if (number == 22) {
        printf("ten sextillion\n");
    }
    else {
    if (number == 23) {
        printf("one hundred sextillion\n");
    }
    else {
    if (number == 24) {
        printf("one septillion\n");
    }
    else {
    if (number == 25) {
        printf("ten septillion\n");
    }
    else {
    if (number == 26) {
        printf("one hundred septillion\n");
    }
    else {
    if (number == 27) {
        printf("one octillion\n");
    }
    else {
    if (number == 28) {
        printf("ten octillion\n");
    }
    else {
    if (number == 29) {
        printf("one hundred octillion\n");
    }
    else {
    if (number == 30) {
        printf("one nonillion\n");
    }
    else {
    if (number == 100) {
        printf("ten dogtrigintillion\n");
    }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}

    return (EXIT_SUCCESS);
}
/*
 * File:   main.c
 * Author: student
 *
 * Created on February 21, 2011, 10:26 PM
 */

#include <stdio.h>
#include <stdlib.h>

/*
 *
 */
int main(int argc, char** argv, int num1) {
    printf("Enter a positive integer: ");
    scanf("%d",&num1);
    int number = num1;
    if (number == 6) {
        printf("Number is perfect\n");
    }
    else {
    if (number == 28) {
        printf("Number is perfect\n");
    }
    else {
    if (number == 496) {
        printf("Number is perfect\n");
    }
    else {
    if (number == 8128) {
        printf("Number is perfect\n");
    }
    else {
    if (number == 33550336) {
        printf("Number is perfect\n");
    }
    else {
    if (number == 858969056) {
        printf("Number is perfect\n");
    }
    else {
        printf("Number is not perfect\n");
            return (EXIT_SUCCESS);
    }}}}}}
   
    return (EXIT_SUCCESS);
}