I am fairly new to Java, and I am trying to build a program that prints a calendar in the format below. It is supposed to start the calendar using the current date and only creates the calendar 1 month ahead.
Example:
October 26, 2016.
Su M T W T F S
[October]
| | | | | 27 | 28 | 29 |
| 30 | 31 | | | | | |
[November]
| | | 1 | 2 | 3 | 4 | 5 |
| 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 13 | 14 | 15 | 16 | 17 | 18 | 19 |
| 20 | 21 | 22 | 23 | 24 | 25 | 26 |
I have written as much as I can, but I keep running into issues when getting to the actual coding. For example, I can't figure out how to start the calendar on the correct day of the week and I have trouble printing the correct amount of weeks in a month. Should I redo my code so that I use calendar = new GregorianCalendar()? Or should I just use instanceOf() and continue messing with the Calendar class?
This is as much code as I could write without breaking my calendar.
StringBuilder calendarString = new StringBuilder();
Calendar calendar = Calendar.getInstance();
int maxDaysOfMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
int dayOfMonth = Calendar.DAY_OF_WEEK;
int weekOfMonth = Calendar.WEEK_OF_MONTH;
int theMonth = Calendar.MONTH;
String month;
switch(theMonth) { // Months start with 0
case 0: month = "January"; break;
case 1: month = "February"; break;
case 2: month = "March"; break;
case 3: month = "April"; break;
case 4: month = "May"; break;
case 5: month = "June"; break;
case 6: month = "July"; break;
case 7: month = "August"; break;
case 8: month = "September"; break;
case 9: month = "October"; break;
case 10: month = "November"; break;
default: month = "December"; break;
}
calendarString.append(month + " " + calendar.get(Calendar.DAY_OF_MONTH) + ", ");
calendarString.append(calendar.get(Calendar.YEAR) + "."); // First line ends here (Add Jobs this month)
calendarString.append(System.getProperty("line.separator"));
calendarString.append(System.getProperty("line.separator"));
calendarString.append(" Su ");
calendarString.append(" M ");
calendarString.append(" T ");
calendarString.append(" W ");
calendarString.append(" T ");
calendarString.append(" F ");
calendarString.append(" S ");
calendarString.append(System.getProperty("line.separator"));