Results 1 to 2 of 2
Thread: java help needed
- 01-28-2009, 02:25 AM #1
Member
- Join Date
- Dec 2008
- Posts
- 39
- Rep Power
- 0
java help needed
- i have an assignment to create a text grid. the system will allow the user to specify a row and column in the grid, and specify the character to be placed in the cell. after each modification the grid will be redisplayed.
-must use a 2D array
-it must consist of 3 classes including the driver
-each time the system starts it should start with a blank slate
-and each the user modifies the grid it should ask if they wont to do another modification or exit.
This is what I have so far. i need some help to finish this thing up. If anyone could help i would greatly appreciate it. thanks
public class Cell{
private char letter = ' ';
private int row;
private int column;
public Cell(){
this.row = 0;
this.column = 0;
}
public void setLetter(char _letter){
this.letter = _letter;
}
public char getLetter(){
return this.letter;
}
public void setRow(int _row){
this.row = _row;
}
public int getRow(){
return this.row;
}
public void setColumn(int _column){
this.column = _column;
}
public int getColumn(){
return this.column;
}
}
// new class
import java.util.*;
public class CellInterface {
private int option;
private int columns;
private int rows;
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.cells = new Cell[rows][columns];
for(int r = 0;r<this.cells.length; r++){
for(int c = 0; c<this.cells[r].length;c++){
Cell cell = new Cell();
}
}
this.cellModifier();
}
private void cellModifier(){
while(option == 1)
{
System.out.println("Enter a row: ");
this.rows = sc.nextInt();
System.out.println("Enter a column: ");
this.columns = sc.nextInt();
System.out.println("Enter a letter: ");
System.out.println("Press 1 to modify or 2 to exit ");
}
}
}
// new class
public class CellDriver{
public static void main(String[] args)
{
}
}
- 01-28-2009, 05:33 AM #2
Change class Cell to Cells. This class should have an instance property
private char[][] cells = null;
public Cells(int rows, int columns) {
cells = new char[rows][columns];
// Loop through the rows and columns to set each array entry to ''
}
Add methods
char getCharAt(int row, int column) {...}
void setCharAt(int row, int column) {...}
Your driver class will need access to the CellInterface methods, so make them at least default.
Don't put the prompt for rows, columns logic in the CellInterface constructor. Create a getSetup() method that returns the rows and columns in an int[2].
CellInterface needs methods
int[] getSetup()
char promptForChar()
void displayValues(char[][] chars)
CellDriver should have a main(). Have it create an instance and invoke the instance's run() method.
The constructor need not do anything.
public void run() {
// put your driver logic here
}
1. Prompt for the setup
2. Prompt for cell values, one at a time, until null is returned
3. Display the values
Similar Threads
-
Help needed with downloader in java
By falcommoney in forum New To JavaReplies: 3Last Post: 01-28-2009, 01:31 PM -
Java Programmer Needed
By ALATECjobs in forum Jobs OfferedReplies: 0Last Post: 08-14-2008, 10:48 PM -
Help needed in Java
By javanewbie in forum New To JavaReplies: 2Last Post: 07-08-2008, 07:55 PM -
Java experts needed- 30 minute online Java projects
By michelle in forum Jobs OfferedReplies: 0Last Post: 03-05-2008, 11:47 PM -
Java help needed
By jeneal in forum New To JavaReplies: 0Last Post: 11-21-2007, 03:04 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks