Skip to content

Commit 846483a

Browse files
authored
Merge pull request #275 from sebiwnl/origin-checks-how-many-days-in-given-month
Checks how many days in a given month - including leap year
2 parents b3f619e + 91ea7cc commit 846483a

File tree

2 files changed

+52
-69
lines changed

2 files changed

+52
-69
lines changed

C++/shell_sort.CPP

Lines changed: 0 additions & 69 deletions
This file was deleted.

Java/NoOfDaysInMonth.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
}

0 commit comments

Comments
 (0)