Question - arrays problem

  • (2 Pages)
  • +
  • 1
  • 2

25 Replies - 867 Views - Last Post: 07 May 2012 - 10:51 AM Rate Topic: -----

#1 rik2012  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 09-April 12

Question - arrays problem

Posted 03 May 2012 - 03:33 AM


import javax.swing.JOptionPane ;
import java.util.Random;
public class Program5 {
    public static void main(String[] args) {
	Random rndNumbers = new Random();
    string [] ; person = new int[10];
    string [] table = new int[2][5];

     person[1] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[2] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[3] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[4] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[5] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[6] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[7] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[8] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[9] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[10] = JOptionPane.showInputDialog(null,"Enter FullName");
          

int i;
for(i = 0; i < 5; i++){
table(1,person(i));
}

for(i = 6; i < 10; i++){
table(2,person(i));
}

 
   System.out.println("table1 = " + persons) ;
   System.out.println("table2 = " + persons) ;
   
    

 }

  }




I'm am trying to place 10 people around two tables of 5 at each table randomly which i need help to get this program running. it does not allow me to javac the program because there is an error in the code which i don't know.can someone help me to get this program to run? i am new to java and still don't understand all aspect at this point. i don't know what the errors is or what to do.

Is This A Good Question/Topic? 0
  • +

Replies To: Question - arrays problem

#2 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1362
  • View blog
  • Posts: 3,002
  • Joined: 30-January 11

Re: Question - arrays problem

Posted 03 May 2012 - 04:12 AM

From a quick look at your code -

1. Line 6 you have a semi-colon in the middle
2. In Java Strings have to have a capital 'S' - String not string
3. Line 7 you are trying to put a 2d array into a 1d array
4. Line 23 and 27 you use square brackets to denote locations in arrays - [2][person[i]]
5. Line 32 and 33 persons does not exist. Plus that will not work out like you thing it will anyways.

If you don't know what I'm talking about then I suggest you go back and learn the principlies of arrays before you try and make a program using them.

Good luck.
Was This Post Helpful? 0
  • +
  • -

#3 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2197
  • View blog
  • Posts: 5,224
  • Joined: 10-September 10

Re: Question - arrays problem

Posted 03 May 2012 - 04:27 AM

You should know by now to post your errors, copied and pasted into your posts. We shouldn't have to beta test your code to help you.
Was This Post Helpful? 0
  • +
  • -

#4 rik2012  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 09-April 12

Re: Question - arrays problem

Posted 03 May 2012 - 04:53 AM

View PostRyano121, on 03 May 2012 - 04:12 AM, said:

From a quick look at your code -

1. Line 6 you have a semi-colon in the middle
2. In Java Strings have to have a capital 'S' - String not string
3. Line 7 you are trying to put a 2d array into a 1d array
4. Line 23 and 27 you use square brackets to denote locations in arrays - [2][person[i]]
5. Line 32 and 33 persons does not exist. Plus that will not work out like you thing it will anyways.

If you don't know what I'm talking about then I suggest you go back and learn the principlies of arrays before you try and make a program using them.

Good luck.


I have fixed line 6 and also changed the string to Capital and also changed line 23 and 27. it is still showing errors in line 23 and 27 due to the brackets
Was This Post Helpful? 0
  • +
  • -

#5 rik2012  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 09-April 12

Re: Question - arrays problem

Posted 03 May 2012 - 05:02 AM

View PostGregBrannon, on 03 May 2012 - 04:27 AM, said:

You should know by now to post your errors, copied and pasted into your posts. We shouldn't have to beta test your code to help you.



import javax.swing.JOptionPane ;

import java.util.Random;

public class Program5 {

    public static void main(String[] args) {
    Random rndNumbers = new Random();

    string [] ; person = new int[10];

    string [] table = new int[2][5];


     person[1] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[2] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[3] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[4] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[5] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[6] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[7] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[8] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[9] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[10] = JOptionPane.showInputDialog(null,"Enter FullName");

           

 

int i;

for(i = 0; i < 5; i++){

table(1,person(i));

}

 

for(i = 6; i < 10; i++){
table(2,person(i));

}


   System.out.println("table1 = " + persons) ;

   System.out.println("table2 = " + persons) ;

 }
  }




i am trying to put 10 people around two table in randomly which at the moment i don't know how to get this working. i also don't know how to fix these errors.
Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

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

Reputation: 8325
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Question - arrays problem

Posted 03 May 2012 - 09:54 AM

these 2 statements are not valid Java statements.

    string [] ; person = new int[10];
    string [] table = new int[2][5];


What are you trying to achieve ?
Was This Post Helpful? 0
  • +
  • -

#7 rik2012  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 09-April 12

Re: Question - arrays problem

Posted 03 May 2012 - 01:03 PM

View Postpbl, on 03 May 2012 - 09:54 AM, said:

these 2 statements are not valid Java statements.

    string [] ; person = new int[10];
    string [] table = new int[2][5];


What are you trying to achieve ?


i am trying to place 10 people around at two tables, which the people will be randomly be placed on each table.
Was This Post Helpful? 0
  • +
  • -

#8 pbl  Icon User is offline

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

Reputation: 8325
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Question - arrays problem

Posted 03 May 2012 - 01:47 PM

That is a very high level description already described in your first topic.

Now back to these 2 statements.
First String is String not string
the ; goes to the end of a statement
if person is a String array it can't be new int[10]. You can't store int in String
If table is a Straing array you can't store a int[][] into it
Was This Post Helpful? 0
  • +
  • -

#9 rik2012  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 09-April 12

Re: Question - arrays problem

Posted 04 May 2012 - 02:19 PM

View Postpbl, on 03 May 2012 - 01:47 PM, said:

That is a very high level description already described in your first topic.

Now back to these 2 statements.
First String is String not string
the ; goes to the end of a statement
if person is a String array it can't be new int[10]. You can't store int in String
If table is a Straing array you can't store a int[][] into it


can you help me to fix this code? i don't know what to do
Was This Post Helpful? 0
  • +
  • -

#10 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2197
  • View blog
  • Posts: 5,224
  • Joined: 10-September 10

Re: Question - arrays problem

Posted 04 May 2012 - 02:25 PM

Two tables, 5 seats each = 10 seats total, filled randomly with 10 people. It doesn't seem that hard.

Without posting any code, describe how you're trying to randomly fill the 10 seats.
Was This Post Helpful? 0
  • +
  • -

#11 rik2012  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 09-April 12

Re: Question - arrays problem

Posted 04 May 2012 - 02:33 PM

View PostGregBrannon, on 04 May 2012 - 02:25 PM, said:

Two tables, 5 seats each = 10 seats total, filled randomly with 10 people. It doesn't seem that hard.

Without posting any code, describe how you're trying to randomly fill the 10 seats.



import javax.swing.JOptionPane ;

import java.util.Random;

public class Program5 {

    public static void main(String[] args) {

    Random rndNumbers = new Random();

    string [] ; person = new int[10];

    string [] table = new int[2][5];

     person[1] = JOptionPane.showInputDialog(null,"Enter FullName");

     person[2] = JOptionPane.showInputDialog(null,"Enter FullName");

     person[3] = JOptionPane.showInputDialog(null,"Enter FullName");

     person[4] = JOptionPane.showInputDialog(null,"Enter FullName");

     person[5] = JOptionPane.showInputDialog(null,"Enter FullName");

     person[6] = JOptionPane.showInputDialog(null,"Enter FullName");

     person[7] = JOptionPane.showInputDialog(null,"Enter FullName");

     person[8] = JOptionPane.showInputDialog(null,"Enter FullName");

     person[9] = JOptionPane.showInputDialog(null,"Enter FullName");

     person[10] = JOptionPane.showInputDialog(null,"Enter FullName");

int i;

 

for(i = 0; i < 5; i++){

 

table(1,person(i));
 
}

for(i = 6; i < 10; i++){

table(2,person(i));

 

}

   System.out.println("table1 = " + persons) ;

 
   System.out.println("table2 = " + persons) ;

 

 }
  }




i don't know how to do this. this is the code so far what i think . i believe there are some errors which i don't know what to do. i am a new leaner to java so i don't fully understand everything at the moment. could you help me please. at this point it don't know if I'm doing it correct
Was This Post Helpful? 0
  • +
  • -

#12 pbl  Icon User is offline

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

Reputation: 8325
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Question - arrays problem

Posted 04 May 2012 - 07:47 PM

If you are a beginner in Java don't start with array
We told you at least 3 times that is String not string
We told you at least twice that you cannot put int[][ into String
We told you that the ; in the middle of a stement is not valid syntax

Here to let you start as you don't seem to read our posts

public static void main(String[] args) {

   String[] person = new String[10];
   for(int i = 0; i < person.length; ++i) {
     person[i] = JOptionPane.showInputDialog(null,"Enter FullName");
   }

   System.out.println("The " + person.length + " are: ");
   for(int i = 0; i < person.length; ++i)
     System.out.println(i + ") " + person[i]);
}


Was This Post Helpful? 0
  • +
  • -

#13 rik2012  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 09-April 12

Re: Question - arrays problem

Posted 05 May 2012 - 01:08 PM

View Postpbl, on 04 May 2012 - 07:47 PM, said:

If you are a beginner in Java don't start with array
We told you at least 3 times that is String not string
We told you at least twice that you cannot put int[][ into String
We told you that the ; in the middle of a stement is not valid syntax

Here to let you start as you don't seem to read our posts

public static void main(String[] args) {

   String[] person = new String[10];
   for(int i = 0; i < person.length; ++i) {
     person[i] = JOptionPane.showInputDialog(null,"Enter FullName");
   }

   System.out.println("The " + person.length + " are: ");
   for(int i = 0; i < person.length; ++i)
     System.out.println(i + ") " + person[i]);


[code]

import javax.swing.JOptionPane ;
import java.util.Random;
public class Program {
public static void main(String[] args) {

 

   String[] person = new String[21];

   for(int i = 0; i < 9; ++i) {
   for(int i = 9; i <20; ++i) {
   
   
   



     person[i] = JOptionPane.showInputDialog(null,"Enter FullName");

   }
   }
   
   System.out.println("Table1");
   
   for(int i = 0; i < person.length; ++i)

   System.out.println(i + ") " + person[i]);
    
   System.out.println("Table2");
   
   for(int i = 0; i < person.length; ++i)

   System.out.println(i + ") " + person[i]);
   
}
}




thank you for your help. i have edit the code and am i doing this correct? i am putting ten people at per table with two table of 10 people but no more than ten people per table?







}
[/code]

Was This Post Helpful? 0
  • +
  • -

#14 rik2012  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 09-April 12

Re: Question - arrays problem

Posted 05 May 2012 - 02:28 PM

import javax.swing.JOptionPane ;
import java.util.Random;
public class Program5 {
    public static void main(String[] args) {
	Random rndNumbers = new Random();
    string [] person = new int[32];
    string [] table = new int[4][8];


    int i;
    for(i = 0; i < 7; i++){
    table[1][person[i]];
    }

    for(i = 8; i < 15; i++){
    table[2][person[i]];
    }

    for(i = 16; i < 23; i++){
    table[3][person[i]];
    }

    for(i = 24; i < 31; i++){
    table[4]person[i]];
    }

     person[0] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[1] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[2] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[3] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[4] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[5] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[6] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[7] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[8] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[9] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[10] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[11] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[12] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[13] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[14] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[15] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[16] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[17] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[18] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[19] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[20] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[21] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[22] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[23] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[24] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[25] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[26] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[27] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[28] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[29] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[30] = JOptionPane.showInputDialog(null,"Enter FullName");
     person[31] = JOptionPane.showInputDialog(null,"Enter FullName");


   System.out.println("table1 = " + person) ;
   System.out.println("table2 = " + person) ;
   System.out.println("table3 = " + person) ;
   System.out.println("table4 = " + person) ;
    

 }

  }




 




from this code i am trying to place 32 people around 4 table which each table must have 8 people. I'm not sure if this is the correct code i have created. can someone show me what errors i have made for me to fix them?

This post has been edited by rik2012: 05 May 2012 - 02:30 PM

Was This Post Helpful? 0
  • +
  • -

#15 RookieC++User  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 07-December 10

Re: Question - arrays problem

Posted 05 May 2012 - 02:39 PM

In java a string is declared as String, read the earlier posts. You cannot store an int in to a String array, it has to be a string. Also why don't you just run a loop asking for full names, until the loop hits the end of the array? Then once the array is full, just randomly place people at random spots. If I am understanding your original problem correctly.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2