Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
agile-java
/
AgileJavaAndroid
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
601e4709
authored
Jun 01, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
created method getAverageGpaForPartTimeStudents + language tests
parent
58c4f184
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
81 additions
and
4 deletions
app/src/main/java/com/example/paktalin/agilejava/Session.java
app/src/test/java/com/example/paktalin/agilejava/SessionTest.java
app/src/test/java/com/example/paktalin/agilejava/language_tests/LoopTest.java
app/src/main/java/com/example/paktalin/agilejava/Session.java
View file @
601e4709
...
...
@@ -42,6 +42,19 @@ public abstract class Session implements Comparable<Session>{
student
.
addCredits
(
numberOfCredits
);
}
double
getAverageGpaForPartTimeStudents
()
{
double
total
=
0
;
int
counter
=
0
;
for
(
Student
student
:
getAllStudents
())
if
(!
student
.
isFullTime
())
{
counter
++;
total
+=
student
.
getGpa
();
}
return
total
/
counter
;
}
protected
abstract
int
getSessionLength
();
Date
getEndDate
()
{
GregorianCalendar
calendar
=
new
GregorianCalendar
();
calendar
.
setTime
(
getStartDate
());
...
...
@@ -59,22 +72,23 @@ public abstract class Session implements Comparable<Session>{
return
students
;
}
protected
abstract
int
getSessionLength
();
Date
getStartDate
()
{
return
startDate
;
}
int
getNumberOfStudents
()
{
return
students
.
size
();
}
String
getDepartment
()
{
return
department
;
}
String
getNumber
()
{
return
number
;
}
Student
get
(
int
index
)
{
return
students
.
get
(
index
);
}
}
app/src/test/java/com/example/paktalin/agilejava/SessionTest.java
View file @
601e4709
...
...
@@ -65,4 +65,30 @@ abstract public class SessionTest extends TestCase {
Session
session
=
createSession
(
"ENGL"
,
"200"
,
startDate
);
assertEquals
(
getExpectedEndDate
(),
session
.
getEndDate
());
}
public
void
testAverageGpaForPartTimeStudents
()
{
session
.
enroll
(
createFullTimeStudent
());
assertEquals
(
1
,
session
.
getNumberOfStudents
());
createPartTimer
(
"1"
,
Student
.
Grade
.
A
);
assertEquals
(
2
,
session
.
getNumberOfStudents
());
createPartTimer
(
"2"
,
Student
.
Grade
.
D
);
assertEquals
(
3
,
session
.
getNumberOfStudents
());
assertEquals
(
2.5
,
session
.
getAverageGpaForPartTimeStudents
(),
0.05
);
}
private
void
createPartTimer
(
String
name
,
Student
.
Grade
grade
)
{
Student
partTimer
=
new
Student
(
name
);
partTimer
.
addGrade
(
grade
);
session
.
enroll
(
partTimer
);
assertFalse
(
partTimer
.
isFullTime
());
assertEquals
(
grade
.
getPoints
(),
partTimer
.
getGpa
(),
0.05
);
}
private
Student
createFullTimeStudent
()
{
Student
student
=
new
Student
(
"a"
);
student
.
addCredits
(
Student
.
CREDITS_REQUIRED_FOR_FULL_TIME
);
return
student
;
}
}
app/src/test/java/com/example/paktalin/agilejava/language_tests/LoopTest.java
View file @
601e4709
...
...
@@ -31,13 +31,50 @@ public class LoopTest extends TestCase {
assertFalse
(
isPalindrome
(
"abbaa"
));
}
public
void
testFibonacci
()
{
assertEquals
(
0
,
fib
(
0
));
assertEquals
(
1
,
fib
(
1
));
assertEquals
(
1
,
fib
(
2
));
assertEquals
(
2
,
fib
(
3
));
assertEquals
(
3
,
fib
(
4
));
assertEquals
(
5
,
fib
(
5
));
}
private
boolean
isPalindrome
(
String
string
){
int
limit
=
string
.
length
()
/
2
;
for
(
int
forward
=
0
,
backward
=
string
.
length
()
-
1
;
forward
<
string
.
length
()
;
forward
<
limit
;
forward
++,
backward
--)
if
(
string
.
charAt
(
forward
)
!=
string
.
charAt
(
backward
))
return
false
;
return
true
;
}
private
int
fib
(
int
x
)
{
if
(
x
==
0
)
return
0
;
if
(
x
==
1
)
return
1
;
return
fib
(
x
-
1
)
+
fib
(
x
-
2
);
}
public
void
testEndTrim
()
{
assertEquals
(
""
,
endTrim
(
""
));
assertEquals
(
" x"
,
endTrim
(
" x "
));
assertEquals
(
"y"
,
endTrim
(
"y"
));
assertEquals
(
"xaxa"
,
endTrim
(
"xaxa"
));
assertEquals
(
""
,
endTrim
(
" "
));
assertEquals
(
"xxx"
,
endTrim
(
"xxx "
));
}
private
String
endTrim
(
String
source
)
{
int
i
=
source
.
length
()
-
1
;
while
(
i
>=
0
)
{
if
(
source
.
charAt
(
i
)
!=
' '
)
break
;
i
--;
}
return
source
.
substring
(
0
,
i
+
1
);
}
}
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