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
58c4f184
authored
Jun 01, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Is able to split student name into firstName, lastName and middleName
parent
ce57dcf8
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
111 additions
and
25 deletions
app/src/main/java/com/example/paktalin/agilejava/Session.java
app/src/main/java/com/example/paktalin/agilejava/Student.java
app/src/test/java/com/example/paktalin/agilejava/AllTests.java
app/src/test/java/com/example/paktalin/agilejava/StudentTest.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 @
58c4f184
...
...
@@ -17,7 +17,6 @@ public abstract class Session implements Comparable<Session>{
private
String
number
;
private
List
<
Student
>
students
=
new
ArrayList
<>();
private
Date
startDate
;
private
static
int
count
=
0
;
private
int
numberOfCredits
;
protected
Session
(
String
department
,
String
number
,
Date
startDate
)
{
...
...
app/src/main/java/com/example/paktalin/agilejava/Student.java
View file @
58c4f184
...
...
@@ -9,6 +9,7 @@ import java.util.List;
class
Student
{
private
String
name
;
private
String
firstName
=
""
,
middleName
=
""
,
lastName
;
private
int
credits
;
static
final
int
CREDITS_REQUIRED_FOR_FULL_TIME
=
12
;
static
final
String
IN_STATE
=
"CO"
;
...
...
@@ -27,37 +28,52 @@ class Student {
}
}
Student
(
String
n
ame
)
{
this
.
name
=
name
;
Student
(
String
fullN
ame
)
{
setNames
(
fullName
)
;
credits
=
0
;
}
String
getName
(
)
{
return
name
;
void
addCredits
(
int
credits
)
{
this
.
credits
+=
credits
;
}
boolean
isFullTime
(
)
{
return
credits
>=
Student
.
CREDITS_REQUIRED_FOR_FULL_TIME
;
void
addGrade
(
Grade
grade
)
{
grades
.
add
(
grade
)
;
}
int
getCredits
()
{
return
credits
;
private
void
setNames
(
String
fullName
)
{
this
.
name
=
fullName
;
String
[]
nameSplit
=
fullName
.
split
(
" "
);
switch
(
nameSplit
.
length
){
case
1
:
lastName
=
nameSplit
[
0
];
break
;
case
2
:
firstName
=
nameSplit
[
0
];
lastName
=
nameSplit
[
1
];
break
;
default
:
firstName
=
nameSplit
[
0
];
middleName
=
nameSplit
[
1
];
lastName
=
nameSplit
[
2
];
break
;
}
}
void
addCredits
(
int
credits
)
{
this
.
credits
+=
credits
;
void
setState
(
String
state
)
{
this
.
state
=
state
.
toUpperCase
()
;
}
boolean
isInState
(
)
{
return
state
.
equals
(
Student
.
IN_STATE
)
;
void
setGradingStrategy
(
HonorsGradingStrategy
gradingStrategy
)
{
this
.
gradingStrategy
=
gradingStrategy
;
}
void
setState
(
String
state
)
{
this
.
state
=
state
.
toUpperCase
()
;
boolean
isFullTime
(
)
{
return
credits
>=
Student
.
CREDITS_REQUIRED_FOR_FULL_TIME
;
}
void
addGrade
(
Grade
grade
)
{
grades
.
add
(
grade
);
boolean
isInState
(
)
{
return
state
.
equals
(
Student
.
IN_STATE
);
}
double
getGpa
()
{
...
...
@@ -69,7 +85,23 @@ class Student {
return
total
/
grades
.
size
();
}
void
setGradingStrategy
(
HonorsGradingStrategy
gradingStrategy
)
{
this
.
gradingStrategy
=
gradingStrategy
;
int
getCredits
()
{
return
credits
;
}
String
getName
()
{
return
name
;
}
String
getFirstName
()
{
return
firstName
;
}
String
getLastName
()
{
return
lastName
;
}
String
getMiddleName
()
{
return
middleName
;
}
}
app/src/test/java/com/example/paktalin/agilejava/AllTests.java
View file @
58c4f184
package
com
.
example
.
paktalin
.
agilejava
;
import
com.example.paktalin.agilejava.language_tests.LanguageTests
;
import
com.example.paktalin.agilejava.language_tests.LoopTest
;
import
com.example.paktalin.agilejava.language_tests.SuperClassTest
;
import
com.example.paktalin.agilejava.summer.SummerCourseSession
;
...
...
@@ -28,6 +29,7 @@ public class AllTests extends TestSuite {
suite
.
addTestSuite
(
LanguageTests
.
class
);
suite
.
addTestSuite
(
SuperClassTest
.
class
);
suite
.
addTestSuite
(
LoopTest
.
class
);
return
suite
;
}
}
app/src/test/java/com/example/paktalin/agilejava/StudentTest.java
View file @
58c4f184
...
...
@@ -10,13 +10,15 @@ import junit.framework.TestCase;
public
class
StudentTest
extends
TestCase
{
public
void
testCreate
()
{
final
String
firstStudentName
=
"Jane Doe"
;
Student
student
=
new
Student
(
firstStudentName
);
assertEquals
(
firstStudentName
,
student
.
getName
());
Student
student
=
new
Student
(
"Jane Doe"
);
verifyNamesCorrect
(
student
,
"Jane Doe"
,
"Jane"
,
"Doe"
,
""
);
final
String
secondStudentName
=
"Joe Blow"
;
Student
secondStudent
=
new
Student
(
secondStudentName
);
assertEquals
(
secondStudentName
,
secondStudent
.
getName
());
student
=
new
Student
(
"Blow"
);
verifyNamesCorrect
(
student
,
"Blow"
,
""
,
"Blow"
,
""
);
student
=
new
Student
(
"Raymond Douglas Davies"
);
verifyNamesCorrect
(
student
,
"Raymond Douglas Davies"
,
"Raymond"
,
"Davies"
,
"Douglas"
);
}
public
void
testStudentStatus
()
{
...
...
@@ -88,4 +90,12 @@ public class StudentTest extends TestCase {
student
.
setGradingStrategy
(
new
HonorsGradingStrategy
());
return
student
;
}
private
void
verifyNamesCorrect
(
Student
student
,
String
name
,
String
firstName
,
String
lastName
,
String
middleName
)
{
assertEquals
(
name
,
student
.
getName
());
assertEquals
(
firstName
,
student
.
getFirstName
());
assertEquals
(
lastName
,
student
.
getLastName
());
assertEquals
(
middleName
,
student
.
getMiddleName
());
}
}
app/src/test/java/com/example/paktalin/agilejava/language_tests/LoopTest.java
0 → 100644
View file @
58c4f184
package
com
.
example
.
paktalin
.
agilejava
.
language_tests
;
import
junit.framework.TestCase
;
/**
* Created by Paktalin on 01/06/2018.
*/
public
class
LoopTest
extends
TestCase
{
private
String
[]
array
;
@Override
protected
void
setUp
()
throws
Exception
{
array
=
new
String
[]{
"apple"
,
"a"
,
"banana"
,
"k"
,
"grapefruit"
,
"pineapple"
};
}
public
void
testMultipleConditionsLoop
()
{
int
i
,
count
;
for
(
i
=
0
,
count
=
0
;
i
<
array
.
length
;
i
++)
if
(
array
[
i
].
length
()
>
1
)
count
++;
assertEquals
(
4
,
count
);
}
public
void
testPalindrome
()
{
assertFalse
(
isPalindrome
(
"abcd"
));
assertTrue
(
isPalindrome
(
"abba"
));
assertTrue
(
isPalindrome
(
""
));
assertFalse
(
isPalindrome
(
"abbaa"
));
}
private
boolean
isPalindrome
(
String
string
){
for
(
int
forward
=
0
,
backward
=
string
.
length
()
-
1
;
forward
<
string
.
length
();
forward
++,
backward
--)
if
(
string
.
charAt
(
forward
)
!=
string
.
charAt
(
backward
))
return
false
;
return
true
;
}
}
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