multi-dimensional array problem

Discuss how to write good code, break bad code, your current pet projects, or the best way to approach novel problems

multi-dimensional array problem

Post by dawodus on Sun Oct 21, 2012 1:49 pm
([msg=70286]see multi-dimensional array problem[/msg])

i have a minor problem basically, i am trying to use a multi dimensional array to show the users inputed cinema movie name and time as output, but when it runs it doesnt finish and has an error im not quite sure what it is that iv done wrong, im sure its one of those really simply ones that im gonna feel like a fool for asking but yolo any help would be good. (code below)

import javax.swing.JOptionPane;


public class assessment5 {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

screening();
System.exit(0);
}

public static String[][] Cinemascreenings() {
// TODO Auto-generated method stub
String filmname;
String filmtime;
String[][] namearray= new String[4][4];

for (int i = 1; i<=4; i++)

{
filmname=JOptionPane.showInputDialog("what is the film on screen "+ i + " today?");
filmtime=JOptionPane.showInputDialog("What time does it start?");
namearray[i][i-i] =filmname;
namearray[i-i][i] =filmtime;

}

return namearray;
}

public static void screening() {

String user;
String[][] film = Cinemascreenings();
user =JOptionPane.showInputDialog(null, "would you like to see the films sceenings tonight? please enter yes if so");
if (user.equalsIgnoreCase("yes"))
{
for (int count = 1; count<=4; count++)
{
JOptionPane.showMessageDialog(null, "CinemaWorld Films Tonight");
JOptionPane.showMessageDialog(null, "Screen "+ count +": "+ film[count][count-count] + film[count-count][count] );
}
}
else
JOptionPane.showInputDialog("You dont want to see the screening okay bye.");
}

}

-- Thu Oct 25, 2012 4:45 pm --

problem fixed it took me a while but i finally understood what i was doing wrong the arrays where out of bound


import javax.swing.JOptionPane;


public class assessment5 {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub


String filmname;
String filmtime;
int x = 5;
int y = 5;
String[][] namearray= new String[x][y];

for (int i = 1; i<=4; i++)
{
filmname=JOptionPane.showInputDialog("what is the film on screen "+ i + " today?");
filmtime=JOptionPane.showInputDialog("What time does it start?");
namearray[0][x-i] =filmname;
namearray[y-i][0] =filmtime;
}
{
String user;
user =JOptionPane.showInputDialog(null, "would you like to see the films sceenings tonight? please enter yes if so");
if (user.equalsIgnoreCase("yes"))
{
for (int count = 1; count<=4; count++)
{
JOptionPane.showMessageDialog(null, "CinemaWorld Films Tonight");
JOptionPane.showMessageDialog(null, "Screen "+ count +": "+ namearray[0][x-count]+ " " + namearray[y-count][0] );
}
}
else
JOptionPane.showInputDialog("You dont want to see the screening okay bye.");

}

}

}
dawodus
New User
New User
 
Posts: 8
Joined: Sat Oct 13, 2012 1:22 pm
Blog: View Blog (0)


Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests

cron