Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
Method exercises
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
ryan.whiteley
Method exercises
Commits
dce0515d
Commit
dce0515d
authored
Nov 05, 2019
by
ryanw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
week five exercises
parents
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
173 additions
and
0 deletions
+173
-0
.classpath
.classpath
+6
-0
.gitignore
.gitignore
+1
-0
.project
.project
+17
-0
Method_Exercises.java
src/weekFiveExercises/Method_Exercises.java
+149
-0
No files found.
.classpath
0 → 100644
View file @
dce0515d
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry
kind=
"src"
path=
"src"
/>
<classpathentry
kind=
"con"
path=
"org.eclipse.jdt.launching.JRE_CONTAINER"
/>
<classpathentry
kind=
"output"
path=
"bin"
/>
</classpath>
.gitignore
0 → 100644
View file @
dce0515d
/bin/
.project
0 → 100644
View file @
dce0515d
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>
weekFiveExercises
</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>
org.eclipse.jdt.core.javabuilder
</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>
org.eclipse.jdt.core.javanature
</nature>
</natures>
</projectDescription>
src/weekFiveExercises/Method_Exercises.java
0 → 100644
View file @
dce0515d
package
weekFiveExercises
;
import
java.util.Random
;
import
java.util.Scanner
;
public
class
Method_Exercises
{
static
Scanner
input
=
new
Scanner
(
System
.
in
);
public
static
void
main
(
String
[]
args
)
{
//System.out.print("The perimeter of this triangle is: " + perim(5, 5, 5));
//System.out.println("\nThe area of this triangle is: " + area(5 ,5, 5));
//tempMenu();
//int n = 10;
//System.out.println(fibonacci(n));
int
n
=
2
;
int
k
=
3
;
//System.out.println(power(n, k));
guessGame
();
}
public
static
int
perim
(
int
a
,
int
b
,
int
c
)
{
int
perim
=
a
+
b
+
c
;
return
perim
;
}
public
static
double
area
(
int
a
,
int
b
,
int
c
)
{
int
s
=
(
a
+
b
+
c
)/
2
;
double
area
=
Math
.
round
(
Math
.
sqrt
(
s
*
(
s
-
a
)
*
(
s
-
b
)
*
(
s
-
c
)));
return
area
;
}
public
static
void
tempMenu
()
{
//repeat menu until the user selects quit
while
(
true
)
{
System
.
out
.
println
(
"Please choose from the following:"
);
System
.
out
.
println
();
System
.
out
.
println
(
"1 - Celcius to Fahrenheit"
);
System
.
out
.
println
(
"2 - Fahrenheit to Clecius"
);
System
.
out
.
println
(
"3 - Quit"
);
String
choice
=
input
.
next
();
switch
(
choice
)
{
case
"1"
:
celToFah
();
break
;
case
"2"
:
fahToCel
();
break
;
default
:
System
.
out
.
println
(
"Goodbye."
);
System
.
exit
(
0
);
break
;
}
}
//while loop ends
}
private
static
void
celToFah
()
{
System
.
out
.
println
(
"Please enter the temp in Celcius: "
);
int
cel
=
input
.
nextInt
();
double
fah
=
9.0
*
cel
/
5
+
32
;
System
.
out
.
println
(
cel
+
"in Fahrenheit is: "
+
fah
);
}
private
static
void
fahToCel
()
{
System
.
out
.
println
(
"Please enter the temp in Fahrenheit: "
);
int
fah
=
input
.
nextInt
();
double
cel
=
(
fah
-
32
)
*
5
/
9
;
System
.
out
.
println
(
fah
+
"in Celcius is "
+
cel
);
}
public
static
int
sum
(
int
x
,
int
y
)
{
int
result
=
x
+
y
;
return
result
;
}
public
static
int
product
(
int
a
,
int
b
,
int
c
)
{
int
result
=
a
*
b
*
c
;
System
.
out
.
println
(
"Result is: "
+
result
);
return
result
;
}
public
static
int
fibonacci
(
int
n
)
{
if
(
n
<=
1
)
return
n
;
return
fibonacci
(
n
-
1
)
+
fibonacci
(
n
-
2
);
}
public
static
double
power
(
double
n
,
double
k
)
{
double
power
=
Math
.
pow
(
n
,
k
);
System
.
out
.
println
(
n
+
"to the power of "
+
k
+
"is: "
);
return
power
;
}
public
static
void
isMultiple
()
{
}
public
static
void
guessGame
()
{
while
(
true
)
{
Random
rand
=
new
Random
();
int
guessNum
=
rand
.
nextInt
(
1001
);
//take guess from user
System
.
out
.
print
(
"Please enter your guess from 1 - 1000: "
);
int
guess
=
input
.
nextInt
();
if
(
guess
>
guessNum
)
{
System
.
out
.
println
(
"Too high, please try again"
);
}
else
if
(
guess
<
guessNum
)
{
System
.
out
.
println
(
"Too low, please try again"
);
}
else
if
(
guess
==
guessNum
)
{
System
.
out
.
println
(
"Correct, that was the right guess!"
);
break
;
}
}
//end of while loop
System
.
out
.
println
(
"Do you want to play again? Y/N"
);
String
choice
=
input
.
next
();
if
(
choice
==
"y"
)
{
guessGame
();
}
else
System
.
out
.
println
(
"Goodbye!"
);
System
.
exit
(
0
);
}
}
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