|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
User Input for arrays
I'm trying to get input from the user for the name of a speech, the start time and the end time of the speech.
Speech [] info = new Speech[7]; info[0] = new Speech ("Superman", 810, 1010); info[1] = new Speech ("Batman", 910, 1010); info[2] = new Speech ("Catwoman", 1010, 1145); info[3] = new Speech ("Incredibles", 1130, 1310); info[4] = new Speech ("Simpsons", 1410, 1500); info[5] = new Speech ("Garfield",1505, 1620); info[6] = new Speech ("Friends", 1605, 1755); so, if I were to input this information into arrays, it could be done but I have to have the user input them into the arrays. public class User { public User(String name, int start, int end) //public static void main(String[] args) { String talkname, again; int startTime, endTime; Scanner scan = new Scanner(System.in); ArrayList listing = new ArrayList(); System.out.println ("Speech : "); speechname = scan.next (); System.out.println ("Start time of speech in 24 hours format: "); startTime = scan.nextInt(); System.out.println("end time of talk in 24 hours format: "); endTime = scan.nextInt(); while (again.equalsIgnoreCase("y")) //accepts both y and Y { int i = 0; i++; listing.add (speechname); listing.add(startTime); listing.add(endTime); speechname = name; startTime = start; endTime = end; System.out.println("Would you like to enter another speech?"); again = scan.next (); } } Any suggestions on how to continue or correct this code to implement it like the listing of arrays(ie batman, superman) earlier on? Thanks. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > User Input for arrays |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|