Java code
package calendar;
import java.util.Scanner;
/**
* This program asks the user for a month, the amount of days in the month, and
* the day of the week the month starts on, then generates a calendar for that
* month with the user entered data.
*/
public class Calendar {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String month;
int daysInMonth;
String dayOfWeek;
String sunday = "Sunday";
String monday = "Monday";
String tuesday = "Tuesday";
String wednesday = "Wednesday";
String thursday = "Thursday";
String friday = "Friday";
String saturday = "Saturday";
System.out.print("Please enter the month for your calendar: ");
month = in.next();
System.out.print("Please enter the number of days in the month: ");
daysInMonth = in.nextInt();
System.out.print("Please enter the day of the week the month starts on: ");
dayOfWeek = in.next();
int daysPerWeek = 7;
int space;
space = daysPerWeek;
System.out.println(month);
System.out.println("S M T W T F S ");
System.out.println("--------------------");
for (int numberOfWeeks = 1; numberOfWeeks <= 1; numberOfWeeks++){
for (int days = 1; days <= daysInMonth; days++){
if (days <= 9){
System.out.print(days);
System.out.print(" ");
}else if (days > 9){
System.out.print(days);
System.out.print("");
}
if ((space + days) % 7 == 0){
System.out.println();
}
else{
System.out.print(" ");
}
}
}
}
}