I'm trying to do a simple program where a user inputs a String "course code" (predefined in an array) and then a loop searches to see what time the input course is at and displays the date/time for that particular course. I also want it to display an error if they input anything that doesn't match.
The problem is that it just loops through the whole array every time and isn't really dependent on the 'if else' for some reason I can't figure out.
import javax.swing.*;
public class ScheduleJ2
{
public static void main(String[] args)
{
String courseList[][]={{"COM101","Mon 08:00"},
{"COM201","Tue 09:00"},
{"COM301","Wed 11:00"},
{"COM315","Thu 14:00"},
{"COM401","Fri 16:00"},};
String courseSelect = JOptionPane.showInputDialog(null, "Enter the Course Code to view the course date and time:\nCOM101\nCOM201\nCOM301\nCOM315\nCOM401");
for(int i = 0; i<courseList.length;i++)
{
if(courseList[i][0].equalsIgnoreCase(courseSelect))
JOptionPane.showMessageDialog(null, "The course you selected is scheduled for: " + courseList[i][1]);
else
courseSelect = JOptionPane.showInputDialog(null, "Error - Course does not exist.\nPlease re-enter your course code:\nCOM101\nCOM201\nCOM301\nCOM315\nCOM401");
}
}
}
Thanks