Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
Lab Week 2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
a-j.towse
Lab Week 2
Commits
79e03410
Commit
79e03410
authored
Feb 14, 2022
by
a-j.towse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MonthBetween
parent
1d45eca2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
70 additions
and
38 deletions
+70
-38
App.java
src/App.java
+70
-38
No files found.
src/App.java
View file @
79e03410
import
java.time.Year
;
//Excercises for week 2
public
class
App
{
...
...
@@ -44,44 +46,22 @@ public class App {
return
(
false
);
}
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
countDays
();
circumference
(
10
);
inigoSpeech
(
6
);
isItALeapYear
(
2016
);
int
month
=
0
;
for
(
month
=
1
;
month
<
14
;
month
++){
switch
(
month
){
case
1
:
System
.
out
.
println
(
"January"
);
break
;
case
2
:
System
.
out
.
println
(
"February"
);
break
;
case
3
:
System
.
out
.
println
(
"March"
);
break
;
case
4
:
System
.
out
.
println
(
"April"
);
break
;
case
5
:
System
.
out
.
println
(
"May"
);
break
;
case
6
:
System
.
out
.
println
(
"June"
);
break
;
case
7
:
System
.
out
.
println
(
"July"
);
break
;
case
8
:
System
.
out
.
println
(
"August"
);
break
;
case
9
:
System
.
out
.
println
(
"September"
);
break
;
case
10
:
System
.
out
.
println
(
"October"
);
break
;
case
11
:
System
.
out
.
println
(
"Novemeber"
);
break
;
case
12
:
System
.
out
.
println
(
"December"
);
break
;
default
:
System
.
out
.
println
(
"Not a valid month"
);
break
;
/*public static String monthCount(int monthNum){
switch(monthNum){
case 1 : return("January");
case 2 : return("February");
case 3 : return("March");
case 4 : return("April");
case 5 : return("May");
case 6 : return("June");
case 7 : return("July");
case 8 : return("August");
case 9 : return("September");
case 10 : return("October");
case 11 : return("Novemeber");
case 12 : return("December");
default : return("Not a valid month");
}
}
while(month < 14){
...
...
@@ -145,7 +125,59 @@ public class App {
break;
}
}while(month < 14);
}*/
public
static
int
daysInMonth
(
int
monthNum
,
int
currentYear
){
if
(
isItALeapYear
(
currentYear
)
==
true
){
int
febDays
=
29
;
}
else
{
int
febDays
=
28
;
}
switch
(
monthNum
){
case
1
:
return
(
31
);
case
2
:
return
(
febDays
);
case
3
:
return
(
31
);
case
4
:
return
(
30
);
case
5
:
return
(
31
);
case
6
:
return
(
30
);
case
7
:
return
(
31
);
case
8
:
return
(
31
);
case
9
:
return
(
30
);
case
10
:
return
(
31
);
case
11
:
return
(
30
);
case
12
:
return
(
31
);
default
:
return
(
1
);
}
}
public
static
int
daysMonthLeft
(
int
startDay
,
int
startMonth
,
int
currentYear
){
int
daysLeft
=
(
daysInMonth
(
startMonth
,
currentYear
)-
startDay
);
return
daysLeft
;
}
public
static
int
daysBetween
(
int
startDay
,
int
startMonth
,
int
startYear
,
int
endDay
,
int
endMonth
,
int
endYear
){
System
.
out
.
println
(
monthCount
(
12
));
int
days
=
0
;
days
+=
daysMonthLeft
(
startDay
,
startMonth
,
currentYear
)
return
days
;
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
/*countDays();
circumference(10);
inigoSpeech(6);
isItALeapYear(2016);
*/
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment