Question: Re-work Assignment #1 onto a DrawingPanel, again SUBMIT DayGrid.java MUST write a method showGrid(graphic, month, year) that produces output, see example above. You also keep
Re-work Assignment #1 onto a DrawingPanel, again SUBMIT DayGrid.java

MUST write a method showGrid(graphic, month, year) that produces output, see example above.
You also keep showGrid(month, year) in this Class as an optional overload of the method.
int month is a parameter, must be 1-12 for the twelve months of the year
int year is a year of the Gregorian calendar (today's European and American standard)
MUST use a method daysInMonth, Exercise #4, page 309, Chapter 4.
showGrid works for any month (1-12), and any year (1900-2100) including leap years.
Suggestion: Use your logic from the last Assignment, just replace (and remove) the System.out calls with appropriate draw calls from Chapter 3g material.
Overload: Two or more methods can have exactly the same name (example: .substring) yet have a different parameter list. In this case, we make another showGrid method, but add a Graphic g parameter, so it's obvious which version is used for any particular call to the method name, the parameter list must match (Chapter 3, page 152).
public class DayGrid {
public static void main(String[] args) {
int month =2;
int year = 2018;
showGrid(month, year);
GregorianCalendar test = new GregorianCalendar(year,month-1,1);
System.out.println("First day:" + test.get(Calendar.DAY_OF_WEEK));
System.exit(0);
}
static void showGrid(int month, int year) {
int startDay = getStartDay(year, month);
System.out.println(" Sun Mon Tue Wed Thu Fri Sat");
System.out.println("+------+------+------+------+------+------+------+");
int numOfDaysInMonth = daysInMonth(year, month);
PrintMonthBody(startDay, numOfDaysInMonth);
System.out.println("+------+------+------+------+------+------+------+");
}
static int getStartDay(int year, int month) {
int startDay1800 = 3;
long totalNumOfDays = getTotalNumOfDays(year, month);
return (int)((totalNumOfDays + startDay1800) % 7);
}
static long getTotalNumOfDays(int year, int month) {
long total = 0;
for (int i = 1800; i
if (isLeapYear(i))
total = total + 366;
else
total = total + 365;
for (int i = 1; i
total = total + daysInMonth(year, i);
return total;
}
static int daysInMonth(int year, int month) {
if (month == 1 || month==3 || month == 5 || month == 7 ||
month == 8 || month == 10 || month == 12)
return 31;
if (month == 4 || month == 6 || month == 9 || month == 11)
return 30;
if (month == 2)
if (isLeapYear(year))
return 29;
else
return 28;
return 0;
}
static boolean isLeapYear(int year) {
if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)))
return true;
return false;
}
static void PrintMonthBody(int startDay, int numOfDaysInMonth) {
int i = 0;
for (i = 0; i
System.out.print("| ");
for (i = 1; i
if (i
System.out.print("| "+i+" ");
else
System.out.print("| "+i+" ");
if ((i + startDay) % 7 == 0)
System.out.print("| ");
}
for (i = 0; i
System.out.print("| ");
System.out.println();
}
}
6 ALWAYS: Name, date, course WHY : Assignment #1 8 and whatever else might be relevant 9 10 11 public class DayGrid 12 public static void main(String[] args) 13 int month = 8; // August in human world int year = 2017; DrawingPanel p = new DrawingPanel(400,200); Graphics g p.getGraphics(); showGrid(g, month, year); // Assignment #2 //showGrld (month, year); // Assignment #1 15 17 18 19 20 21 22 public static void showGrid(Graphics g, int month, int year) 23 // method to display month as a grid Drawing Panel File View Help Sun Mon Tue Wed Thu Fri Sat 10 11 12 13 14 15 16 17 18 19 20 21 272829 30 31 22 23 24 25 26 x=385, y= 176), r=255 g=255 b=255 43
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
