Results 1 to 3 of 3

Thread: please help

  1. #1
    mayhewj7 is offline Member
    Join Date
    Dec 2008
    Posts
    39
    Rep Power
    0

    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:

  2. #2
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    someone posted the same homework problem yesterday.

    please change the title to something meaningful.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  3. #3
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    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)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •