WordRDjava - System.out.print(grid [l][w]);...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.util.Scanner; import java.io.*; public class WordRDjava { private char [][] grid; private int length; private int width; private String dimensionsArray[]; private String gridDimensions; private boolean containsChar = false; public void Word(Scanner input){ gridDimensions = input.nextLine(); dimensionsArray = gridDimensions.split(" "); length = Integer.parseInt(dimensionsArray[0]); width = Integer.parseInt(dimensionsArray[1]); System.out.println(length + " " + width); } public void read(Scanner input) { grid = new char [length][width]; for(int l = 0; l < length; l++){ String line = input.nextLine(); line = line.toLowerCase(); for(int w = 0; w < width; w++){ grid [l][w] = line.charAt(w); } } } public void print() { for(int l = 0; l < length; l++){ System.out.println(); for(int w = 0; w < width; w++){
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: System.out.print(grid [l][w]); System.out.print(&quot; &quot;); } } } public boolean checkHorizontal(String guess) { for(int l = 0; l &lt; length; l++){ String line = String.valueOf(grid[l]); String subLine = &quot;&quot;; for (int g = 0; g &lt; guess.length(); g++){ for(int w = 0; w &lt; width; w++){ if(guess.charAt(g) == grid[l][w]){ if(w + 1 &gt;= guess.length()){ subLine = line.substring(line.indexOf(line.charAt(w)), guess.length()); System.out.println(subLine); if(guess.equals(subLine)){ System.out.println(&quot;Correct!&quot;); } } } } } } return containsChar; } public boolean checkVertical(String guess, Scanner input) { return false; } public boolean checkDiagonal(String guess, Scanner input) { return false; } public String toString(){ return &quot;&quot;; } }...
View Full Document

This note was uploaded on 04/03/2010 for the course COMPSCI 600.107 taught by Professor Houlahan during the Spring '08 term at Johns Hopkins.

Page1 / 2

WordRDjava - System.out.print(grid [l][w]);...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online