All pastes #744167 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-10-21 04:20 UTC
rendered paste body
//Jenny Ye & Sam Gerstenzang Period 8
import java.io.*;
import java.util.*;

public class Crossword{
    char [][] a;

    public Crossword(){
        a = new char[10][12];
        for (int i = 0; i< 10; i++){
            for(int b = 0 ; b <12; b ++){
                a[i][b] = '-';
            }
        }
    }
 public Crossword(int rows, int columns){
        a = new char[rows][columns];
        for (int i =0; i< rows; i ++){
            for  (int b = 0; b< columns; b ++){
                a[i][b]= '-';
            }
        }
    }
    public String toString(){
        String s = new String();
        for (int i = 0; i < a.length; i++){
            for (int j = 0; j < a[i].length; j++){
                s += a[i][j];
            }
            s += "\n";
        }
        return s;
    }
    public void addWord(String word, int startRow, int startColumn, boolean direction){
        if (direction){
            if (startRow <= a.length && (word.length() + startColumn) <= a[0].length){
                for (int i = startColumn; i<(word.length()+ startColumn); i ++){
                    a[startRow][i] = word.charAt(i-startColumn);
                }
            }
        }
        else{
            if(startColumn <= a[0].length && (word.length() + startRow)<= a.length){
                for (int i = startRow; i <(word.length() + startRow); i ++){
                    a[i][startColumn] = word.charAt(i-startRow);
                }
            }
        }
    }
    public static void main(String args[]){
        Crossword x = new Crossword();
        System.out.println(x);
        x.addWord("hello", 4, 5, true);
        System.out.println(x);
        x.addWord("apple",6,7,false);
        System.out.println(x);
        x.addWord("hippopotamus",10,9,false);
        System.out.println(x);
    }
}