Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-29-2009, 05:21 AM
Member
 
Join Date: Dec 2008
Posts: 39
Rep Power: 0
mayhewj7 is on a distinguished road
Default 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:
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 01-29-2009, 05:35 AM
angryboy's Avatar
Senior Member
 
Join Date: Jan 2009
Location: Javaland
Posts: 742
Rep Power: 2
angryboy is on a distinguished road
Default
someone posted the same homework problem yesterday.

please change the title to something meaningful.
__________________
USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-29-2009, 05:40 AM
angryboy's Avatar
Senior Member
 
Join Date: Jan 2009
Location: Javaland
Posts: 742
Rep Power: 2
angryboy is on a distinguished road
Default
oh i see... it WAS you, you just started another thread. that's what confused me.
__________________
USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +2. The time now is 07:48 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org