Well, I don't have your BusyTime or ElapsedTime classes, but here's an example of printing out a 2D array. It's just nested loops. I used Java 5's new format option to make it pretty.
Your toString function shouldn't actually print anything out at all when it's done -- just return a string.
Of course, if I were really doing this, I'd probably just use Java's date classes.
public class Schedule
{
private final int HOURS_IN_DAY = 24;
private int daysInMonth;
private char[][] myArray;
public Schedule(int daysInMonth)
{
this.daysInMonth = daysInMonth;
myArray = new char;
for (int day = 0; day < daysInMonth; ++day) {
for (int hour = 0; hour < HOURS_IN_DAY; ++hour) {
myArray = 'X';
}
}
}
public String toString()
{
// This is quite clearly a hack to get the days of the week to line up with
// the printed schedule. If I had taken more time, these numbers wouldn't
// be hard-coded, but who wants to format a format string? Ick.
String retString = " ";
// This function makes use of Java 5's format option. Yay!
for (int i = 0; i < daysInMonth; ++i) {
retString += String.format("%2c", translateNumberToWeekday(i));
}
for (int hour = 0; hour < HOURS_IN_DAY; ++hour) {
retString += String.format("\n%8s ", translate24to12(hour));
for (int day = 0; day < daysInMonth; ++day) {
retString += String.format("%2c", myArray);
}
}
return retString;
}
private String translate24to12(int hour)
{
if (hour == 0)
return "Midnight";
if (hour == 12)
return "Noon";
if (hour > 12)
return (hour - 12) + ":00 PM";
else
return hour + ":00 AM";
}
private char translateNumberToWeekday(int day)
{
final int val = day % 7;
switch (val) {
case 0:
return 'S';
case 1:
return 'M';
case 2:
return 'T';
case 3:
return 'W';
case 4:
return 'R';
case 5:
return 'F';
case 6:
return 'A';
}
// If we get an X, something is very wrong.
return 'X';
}
}