File tree Expand file tree Collapse file tree 2 files changed +52
-69
lines changed
Expand file tree Collapse file tree 2 files changed +52
-69
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+
2+ /**
3+ * Gives the number of days in the given month
4+ *
5+ * @author Sebastian
6+ * @version 1.0
7+ */
8+ public class NoOfDaysInMonth
9+ {
10+ String month ;
11+ int year ;
12+ int noOfDays ;
13+ Boolean leapYear ;
14+
15+ /**
16+ * Constructor that initializes the fields.
17+ * @param month Assigns the param to the field
18+ * @param year Assign the param to the field
19+ */
20+ public NoOfDaysInMonth (String month , int year ) {
21+ this .month = month ;
22+ this .year = year ;
23+ noOfDays = 0 ;
24+ leapYear = false ;
25+ }
26+
27+ /**
28+ * Checks how many days are in the month and takes leapyear in to consideration.
29+ */
30+ public void NoOfDays () {
31+
32+ if (month .equals ("January" ) || month .equals ("March" ) || month .equals ("May" ) || month .equals ("July" ) || month .equals ("August" ) ||
33+ month .equals ("October" ) || month .equals ("December" )) {
34+ noOfDays = 31 ;
35+ } else if (month .equals ("November" ) || month .equals ("September" ) || month .equals ("June" ) || month .equals ("April" )) {
36+ noOfDays = 30 ;
37+ } else if (month .equals ("February" )) {
38+ if (((year % 400 == 0 ) || ((year % 4 == 0 ) && (year % 100 != 0 )))) {
39+ noOfDays = 29 ;
40+ leapYear = true ;
41+ } else {
42+ noOfDays = 28 ;
43+ }
44+ }
45+ if (leapYear ) {
46+ System .out .println ("There are " + noOfDays + " in " + month + " because its a leap year" );
47+ } else {
48+ System .out .println ("There are " + noOfDays + " in " + month );
49+ }
50+
51+ }
52+ }
You can’t perform that action at this time.
0 commit comments