2 Replies - 1682 Views - Last Post: 04 November 2010 - 09:43 PM Rate Topic: -----

#1 rosamercedes3323  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-November 10

Irregular arrays in methods

Posted 04 November 2010 - 09:32 PM

.

import java.util.Scanner;
public class project {
//-----------------------------------------------------------------------------
private static Scanner keyboard = new Scanner(System.in);
//-----------------------------------------------------------------------------
public static void main(String[] args) {
double row [][];
int positionInRow, numberInRow, rowSize, index, numberOfRows;

System.out.println("Welcome to the Band of the Hour");
System.out.println("-------------------------------");
System.out.print("Please enter number of rows : ");
numberOfRows = keyboard.nextInt();
row= new double [numberOfRows][];
//----Add number of positions
for (index = 0; index < row.length; index++) {
System.out.print("Please enter number of positions in row " + (char)((int) 'A' + index) + ":");
rowSize = keyboard.nextInt();
row [index] = new double [rowSize];
for(positionInRow= 0; positionInRow < row[index].length; positionInRow++){
row[index][positionInRow]= 0.0;
}
displayMenu (row);
}
}
//-----------------------------------------------------------------
private static void displayMenu (double[][] row) {
char command;
do {
System.out.println("(A)dd, ®emove, (P)rint, e(X)it :");
command = keyboard.nextLine().charAt(0);
command = Character.toUpperCase(command);
switch (command){
case 'A':
addMusician(row);
break;
case 'R':
removeMusician(row);
break;
case 'P':
printBandstand(row);
break;
case 'X':
System.out.println("GoodBye");
break;
default:
System.out.println("ERROR: Invalid option, try again :");
}
} while (command!='X');

}
//-----------------------------------------------------------------------------
private static void addMusician(double[][] row) {
//-----------------------------------------------------------------------------
private static void removeMusician(double[][] row) {
//-----------------------------------------------------------------------------
private static void printBandstand(double[][] row) {
int index, positionInRow;

for (index= 0; index < row.length; index++) {
for (positionInRow = 0; positionInRow< row[index].length;
positionInRow++); {
System.out.print(row[index][positionInRow]+ " ");
}
System.out.println();
}
}
//-----------------------------------------------------------------------
}
//=======================================================================








I want to know if my code is ok and how should I go about writing the add and remove methods. How do I add something to an specific row and column and how am i suppose to remove a value? do i set it to null?


Thank you

Is This A Good Question/Topic? 0
  • +

Replies To: Irregular arrays in methods

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8343
  • View blog
  • Posts: 31,890
  • Joined: 06-March 08

Re: Irregular arrays in methods

Posted 04 November 2010 - 09:38 PM

And what is your problem ?
Was This Post Helpful? 0
  • +
  • -

#3 rosamercedes3323  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-November 10

Re: Irregular arrays in methods

Posted 04 November 2010 - 09:43 PM

View Postpbl, on 04 November 2010 - 08:38 PM, said:

And what is your problem ?


In my code I am supposed to have a menu where I can add, remove, print or exit from the program. I do not know what to use in order to add a value to the array in a specific location.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1