19.09.2015 Views

Prentice.Hall.Introduction.to.Java.Programming,.Brief.Version.9th.(2014).[sharethefiles.com]

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

206 Chapter 5 Methods<br />

printCalendar<br />

(main)<br />

readInput<br />

printMonth<br />

printMonthTitle<br />

printMonthBody<br />

getMonthName<br />

getStartDay<br />

getTotalNumberOfDays<br />

getNumberOfDaysInMonth<br />

isLeapYear<br />

FIGURE 5.12<br />

the program.<br />

The structure chart shows the hierarchical relationship of the subproblems in<br />

let printMonth display the year and the month in the stub. Thus, your program may begin<br />

like this:<br />

public class PrintCalendar {<br />

/** Main method */<br />

public static void main(String[] args) {<br />

Scanner input = new Scanner(System.in);<br />

// Prompt the user <strong>to</strong> enter year<br />

System.out.print("Enter full year (e.g., 2012): ");<br />

int year = input.nextInt();<br />

// Prompt the user <strong>to</strong> enter month<br />

System.out.print("Enter month as a number between 1 and 12: ");<br />

int month = input.nextInt();<br />

// Print calendar for the month of the year<br />

printMonth(year, month);<br />

}<br />

/** A stub for printMonth may look like this */<br />

public static void printMonth(int year, int month)<br />

System.out.print(month + " " + year);<br />

}<br />

{<br />

/** A stub for printMonthTitle may look like this */<br />

public static void printMonthTitle(int year, int month)<br />

}<br />

{<br />

/** A stub for getMonthBody may look like this */<br />

public static void printMonthBody(int year, int month)<br />

}<br />

{

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!