Results 1 to 3 of 3
Thread: please help
- 01-29-2009, 04:21 AM #1
Member
- Join Date
- Dec 2008
- Posts
- 39
- Rep Power
- 0
please help
my program needs to print a letter in a specific row and column after asking the questions for which row and column. It will print the letter in the right column but it will only print on the 1st row and the the second or third if i select the third row. I have a seperate cell and driver class but the problem is coming from this class.... Here is the class and what it looks like when it prints out...
If you can help I would greatly appreciate it. Thanks.
import java.util.*;
public class CellInterface {
private int option;
private int columns;
private int rows;
private int cellRow;
private int cellColumn;
private Cell[][] cells;
private Scanner sc = new Scanner(System.in);
public CellInterface(){
System.out.println("How many rows would you like? ");
this.rows = sc.nextInt();
System.out.println("How many columns would you like? ");
this.columns = sc.nextInt();
this.option = 1;
this.cellRow = 0;
this.cellColumn = 0;
this.cells = new Cell[rows][columns];
for(int r = 0; r < this.cells.length; r++){
for(int c = 0; c < this.cells[r].length; c++){
this.cells[r][c] = new Cell(' ');
}
}
this.cellModifier();
}
public void cellModifier(){
while(option == 1){
System.out.println("Enter a row: ");
this.cellRow = sc.nextInt();
System.out.println("Enter a column: ");
this.cellColumn = sc.nextInt();
System.out.println("Enter a letter: ");
this.cells[cellRow][cellColumn].setLetter(sc.next().charAt(0));
this.printGrid();
System.out.println("Press 1 to modify: Press 2 to exit: ");
this.option = sc.nextInt();
}
}
public void printGrid(){
for(int r = 0; r < this.cells.length; r++){
for(int c = 0; c < this.cells[r].length; c++){
System.out.print(this.cells[r][c].getLetter() + '\n');
}
}
}
}
this is what it looks like when its printed:
How many rows would you like?
5
How many columns would you like?
5
Enter a row:
2
Enter a column:
4
Enter a letter:
A
42424242424242424242424242427542424242424242424242
Press 1 to modify: Press 2 to exit:
- 01-29-2009, 04:35 AM #2
someone posted the same homework problem yesterday.
please change the title to something meaningful.USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
- 01-29-2009, 04:40 AM #3
oh i see... it WAS you, you just started another thread. that's what confused me.
USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks