Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
agile-java
/
ChessAndroid
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
6502560a
authored
Jul 05, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lesson 7 Exercise 1
parent
7f46051f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
130 additions
and
0 deletions
.idea/modules.xml
.idea/vcs.xml
app/src/main/java/com/example/paktalin/agilejava_exercises/Factorial.java
app/src/test/java/com/example/paktalin/agilejava_exercises/AllTests.java
app/src/test/java/com/example/paktalin/agilejava_exercises/FactorialTest.java
.idea/modules.xml
0 → 100644
View file @
6502560a
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"ProjectModuleManager"
>
<modules>
<module
fileurl=
"file://$PROJECT_DIR$/AgileJava_Exercises.iml"
filepath=
"$PROJECT_DIR$/AgileJava_Exercises.iml"
/>
<module
fileurl=
"file://$PROJECT_DIR$/app/app.iml"
filepath=
"$PROJECT_DIR$/app/app.iml"
/>
</modules>
</component>
</project>
\ No newline at end of file
.idea/vcs.xml
0 → 100644
View file @
6502560a
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"VcsDirectoryMappings"
>
<mapping
directory=
"$PROJECT_DIR$"
vcs=
"Git"
/>
</component>
</project>
\ No newline at end of file
app/src/main/java/com/example/paktalin/agilejava_exercises/Factorial.java
0 → 100644
View file @
6502560a
package
com
.
example
.
paktalin
.
agilejava_exercises
;
class
Factorial
{
static
int
getWhileFactorial
(
int
number
)
{
int
factorial
;
if
(
number
==
0
||
number
==
1
)
factorial
=
1
;
else
{
int
increment
=
1
;
factorial
=
increment
;
while
(
increment
<=
number
)
{
factorial
*=
increment
;
increment
++;
}
}
return
factorial
;
}
static
int
getDoWhileFactorial
(
int
number
)
{
int
factorial
;
if
(
number
==
0
||
number
==
1
)
factorial
=
1
;
else
{
int
i
=
1
;
factorial
=
1
;
do
{
factorial
*=
i
;
i
++;
}
while
(
i
<=
number
);
}
return
factorial
;
}
static
int
getForFactorial
(
int
number
)
{
int
factorial
;
if
(
number
==
0
||
number
==
1
)
factorial
=
1
;
else
{
factorial
=
1
;
for
(
int
i
=
1
;
i
<=
number
;
i
++)
{
factorial
*=
i
;
}
}
return
factorial
;
}
static
int
getBreakFactorial
(
int
number
)
{
int
factorial
;
if
(
number
==
0
||
number
==
1
)
factorial
=
1
;
else
{
int
i
=
1
;
factorial
=
1
;
while
(
true
)
{
if
(
i
>
number
)
break
;
factorial
*=
i
;
i
++;
}
}
return
factorial
;
}
}
app/src/test/java/com/example/paktalin/agilejava_exercises/AllTests.java
View file @
6502560a
...
...
@@ -27,6 +27,8 @@ public class AllTests extends TestSuite {
suite
.
addTestSuite
(
RookTest
.
class
);
suite
.
addTestSuite
(
KnightTest
.
class
);
suite
.
addTestSuite
(
FactorialTest
.
class
);
return
suite
;
}
}
app/src/test/java/com/example/paktalin/agilejava_exercises/FactorialTest.java
0 → 100644
View file @
6502560a
package
com
.
example
.
paktalin
.
agilejava_exercises
;
import
junit.framework.TestCase
;
public
class
FactorialTest
extends
TestCase
{
public
void
testWhile
()
{
int
factorial
=
Factorial
.
getWhileFactorial
(
5
);
assertEquals
(
getFactorial
(
5
),
factorial
);
factorial
=
Factorial
.
getWhileFactorial
(
4
);
assertEquals
(
getFactorial
(
4
),
factorial
);
factorial
=
Factorial
.
getWhileFactorial
(
3
);
assertEquals
(
getFactorial
(
3
),
factorial
);
}
public
void
testDoWhile
()
{
int
factorial
=
Factorial
.
getDoWhileFactorial
(
5
);
assertEquals
(
getFactorial
(
5
),
factorial
);
factorial
=
Factorial
.
getDoWhileFactorial
(
4
);
assertEquals
(
getFactorial
(
4
),
factorial
);
factorial
=
Factorial
.
getDoWhileFactorial
(
3
);
assertEquals
(
getFactorial
(
3
),
factorial
);
}
public
void
testFor
()
{
int
factorial
=
Factorial
.
getForFactorial
(
5
);
assertEquals
(
getFactorial
(
5
),
factorial
);
factorial
=
Factorial
.
getForFactorial
(
4
);
assertEquals
(
getFactorial
(
4
),
factorial
);
factorial
=
Factorial
.
getForFactorial
(
3
);
assertEquals
(
getFactorial
(
3
),
factorial
);
}
public
void
testBreak
()
{
int
factorial
=
Factorial
.
getBreakFactorial
(
5
);
assertEquals
(
getFactorial
(
5
),
factorial
);
factorial
=
Factorial
.
getBreakFactorial
(
4
);
assertEquals
(
getFactorial
(
4
),
factorial
);
factorial
=
Factorial
.
getBreakFactorial
(
3
);
assertEquals
(
getFactorial
(
3
),
factorial
);
}
private
int
getFactorial
(
int
number
)
{
int
[]
factorials
=
{
1
,
1
,
2
,
6
,
24
,
120
};
return
factorials
[
number
];
}
}
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