I think maybe it's because it has sked[0].length in the for loop perhaps but I was able to, with the code below:
import java.util.Scanner;
public class Scheduler {
public static final String[] time = { "7:30", "8:30", "9:30", "10:30",
"11:30", "1:00", "2:00", "3:00", "4:00" };
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
String input = "";
String[] temp;
String classTime = "";
String day = "";
String course = "";
String[][] sked;
int row = 0;
int col = 0;
sked = new String[9][6];
for (int i =0; i < sked.length; i++)
{
for (int j =0; j < sked[i].length; j++)
sked[i][j] = "";
}
do {
System.out
.println("Please input the Course,Day/s, and Time accordingly.");
input = kb.nextLine();
if (input.isEmpty()) {
break;
}
temp = input.split(",");
course = temp[0].toUpperCase();
day = temp[1].toUpperCase();
if (classTime.matches("[0-9]{1,2}:[0-9]{2}")) {
row = " 7:30 8:30 9:3010:3011:30 1:00 2:00 3:00 4:00"
.indexOf(classTime) / 5;
System.out.println(row);
}
// -------------------------days
// prototype----------------------------------
/*
* if(day.matches ("[MTWHFS]{1,6}")){ for (int i = 0; i <
* day.length(); i++) { col = "MTWHFS".indexOf(day.charAt(i));
* System.out.println(i); } }else{ System.out.println("Error!"); }
*/
/*
* if (day.matches("[MTWHFS]{1,6}")) { for (int i = 0; i <
* day.length(); i++) { col = "MTWHFS".indexOf(day.charAt(i));
* System.out.println(i); if (sked == null) { sked [row][col] =
* course; } else { System.out.println("class is overlapping"); } }
* }
*/
// ---------------------------end days prototype...these are
// failures...------
if (day.matches("[MTWHFS]{1,6}")) {
for (int i = 0; i < day.length(); i++) {
col = "MTWHFS".indexOf(day.charAt(i));
System.out.println(col);
sked[row][col] = course;
}
}
else {
System.out.println("Error!");
}
} while (true);
// ---------------------printout
// prototypes.------------------------------------
/*
*
* System.out.println(); System.out.println(
* "\t\tMonday Tuesday Wednesday Thursday Friday Saturday"
* ); for (int r=0;r<time.length;r++){ System.out.print(time[r] + "\t");
* for (int c=0;c<sked[0].length;c++){ if ( sked[r][c] == null ){
* System.out.print(""); } else { System.out.printf("%-2s",sked[r][c] +
* "\t\t"); } } System.out.println(); }
*/
/*
* System.out.printf("%-5s%10s%10s%10s%10s%10s%10s%n","","M","T","W","H",
* "F","S"); for (int c = 0; c < sked[0].length; c++) {
* System.out.printf("%-5s", time[c]);
*
* for (int r = 0; r < sked.length; r++) { System.out.printf("%10s",
* sked[r][c]); }
*
* System.out.println(); }
*/
System.out
.println("\t\tMonday Tuesday Wednesday Thursday Friday Saturday");
for (int r = 0; r < time.length; r++) { // top to bottom
System.out.println(time[r] + "\t");
for (int c = 0; c < sked[0].length; c++) { // left to right
if (sked[r][c] == null) {
System.out.print("");
}
else {
System.out.printf("%-2s", sked[r][c] + "\t\t");
}
// array elements accessed as table[row][col] ?
}
}
}
}
get this
Please input the Course,Day/s, and Time accordingly.
IT191,MTWHF,7:00
0
1
2
3
4
Please input the Course,Day/s, and Time accordingly.
IT191,MW,7:30
0
2
Please input the Course,Day/s, and Time accordingly.
IT195,T,8:00
1
Please input the Course,Day/s, and Time accordingly.
PEN193,S,8:00
5
Please input the Course,Day/s, and Time accordingly.
Monday Tuesday Wednesday Thursday Friday Saturday
7:30
IT191 IT195 IT191 IT191 IT191 PEN193 8:30
9:30
10:30
11:30
1:00
2:00
3:00
4:00
It was a bit neater than that output shown above but it still had the 7:30 up there in a weird spot and all the classes set to the same time period.