Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
Week 2 Exercises Correct
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
austin.blanke
Week 2 Exercises Correct
Commits
b7f6c6f3
Commit
b7f6c6f3
authored
Feb 14, 2022
by
austin.blanke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Origin
parents
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
192 additions
and
0 deletions
+192
-0
App.java
src/App.java
+192
-0
No files found.
src/App.java
0 → 100644
View file @
b7f6c6f3
import
java.nio.file.attribute.FileOwnerAttributeView
;
public
class
App
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
/*
Week 2 exercises, 14/2/2022, made by Austin Blanke
*/
int
month
=
1
;
countDays
();
Circumference
(
3
);
System
.
out
.
println
(
inigoSpeech
(
10
));
System
.
out
.
println
(
isItALeapYear
(
2021
));
/*
month = 1;
do{
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("November");
break;
case 12: System.out.println("December");
break;
default: System.out.println("Not a valid month");
break;
}
month ++;
}while (month < 14);
month = 1;
while(month < 14){
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("November");
break;
case 12: System.out.println("December");
break;
default: System.out.println("Not a valid month");
break;
}
month ++;
}
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("November");
break;
case 12: System.out.println("December");
break;
default: System.out.println("Not a valid month");
break;
}
} */
}
public
static
void
countDays
(){
int
daysPerWeek
=
7
;
// Ex 2.1
int
numberOfWeeks
=
6
;
// Ex 2.2
int
totalDays
=
daysPerWeek
*
numberOfWeeks
;
// Ex 2.3
boolean
onHoliday
=
false
;
// Ex 2.4
if
(
onHoliday
){
System
.
out
.
println
(
"On holiday"
);}
else
{
System
.
out
.
println
(
"Not on holiday"
);}
}
public
static
void
Circumference
(
int
radius
){
double
approxPI
=
3.14
;
// Ex 2.5
System
.
out
.
println
(
"Circumference: "
+
(
2
*
approxPI
*
radius
*
radius
));
}
public
static
String
inigoSpeech
(
int
numFingers
){
String
greetingString
=
"Hello"
;
// Ex 2.7
String
introductionString
=
"My name is Inigo Montoya"
;
// Ex 2.8
String
reminderString
=
"You killed my father"
;
// Ex 2.9
String
threatString
=
"Prepare to die!"
;
// Ex 2.10
int
fingersOnRightHand
=
numFingers
-
5
;
if
(
fingersOnRightHand
==
6
){
return
(
greetingString
+
", "
+
introductionString
+
", "
+
reminderString
+
", "
+
threatString
);
}
else
{
return
(
"5 fingers, you're good"
);
}
}
public
static
Boolean
isItALeapYear
(
int
year
){
if
(
year
%
4
==
0
){
return
true
;}
else
{
return
false
;}
}
public
static
int
daysInYear
(
int
year
){
if
(
isItALeapYear
(
year
)){
return
366
;}
else
{
return
365
;}
}
public
static
int
daysInYearFrom
(
int
day
,
int
month
,
int
year
){
int
days
=
0
;
for
(
month
=
month
++;
month
<
13
;
month
++){
switch
(
month
){
case
1
:
days
=
days
+
31
;
break
;
case
2
:
days
=
days
+
28
;
break
;
case
3
:
days
=
days
+
31
;
break
;
case
4
:
days
=
days
+
30
;
break
;
case
5
:
days
=
days
+
31
;
break
;
case
6
:
days
=
days
+
30
;
break
;
case
7
:
days
=
days
+
31
;
break
;
case
8
:
days
=
days
+
31
;
break
;
case
9
:
days
=
days
+
30
;
break
;
case
10
:
days
=
days
+
31
;
break
;
case
11
:
days
=
days
+
30
;
break
;
case
12
:
days
=
days
+
31
;
break
;
}
}
}
public
static
int
daysBetween
(
int
startDay
,
int
startMonth
,
int
startYear
,
int
endDay
,
int
endMonth
,
int
endYear
){
}
}
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