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>{
...
@@ -17,7 +17,6 @@ public abstract class Session implements Comparable<Session>{
private
String
number
;
private
String
number
;
private
List
<
Student
>
students
=
new
ArrayList
<>();
private
List
<
Student
>
students
=
new
ArrayList
<>();
private
Date
startDate
;
private
Date
startDate
;
private
static
int
count
=
0
;
private
int
numberOfCredits
;
private
int
numberOfCredits
;
protected
Session
(
String
department
,
String
number
,
Date
startDate
)
{
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;
...
@@ -9,6 +9,7 @@ import java.util.List;
class
Student
{
class
Student
{
private
String
name
;
private
String
name
;
private
String
firstName
=
""
,
middleName
=
""
,
lastName
;
private
int
credits
;
private
int
credits
;
static
final
int
CREDITS_REQUIRED_FOR_FULL_TIME
=
12
;
static
final
int
CREDITS_REQUIRED_FOR_FULL_TIME
=
12
;
static
final
String
IN_STATE
=
"CO"
;
static
final
String
IN_STATE
=
"CO"
;
...
@@ -27,37 +28,52 @@ class Student {
...
@@ -27,37 +28,52 @@ class Student {
}
}
}
}
Student
(
String
n
ame
)
{
Student
(
String
fullN
ame
)
{
this
.
name
=
name
;
setNames
(
fullName
)
;
credits
=
0
;
credits
=
0
;
}
}
String
getName
(
)
{
void
addCredits
(
int
credits
)
{
return
name
;
this
.
credits
+=
credits
;
}
}
boolean
isFullTime
(
)
{
void
addGrade
(
Grade
grade
)
{
return
credits
>=
Student
.
CREDITS_REQUIRED_FOR_FULL_TIME
;
grades
.
add
(
grade
)
;
}
}
int
getCredits
()
{
private
void
setNames
(
String
fullName
)
{
return
credits
;
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
)
{
void
setState
(
String
state
)
{
this
.
credits
+=
credits
;
this
.
state
=
state
.
toUpperCase
()
;
}
}
boolean
isInState
(
)
{
void
setGradingStrategy
(
HonorsGradingStrategy
gradingStrategy
)
{
return
state
.
equals
(
Student
.
IN_STATE
)
;
this
.
gradingStrategy
=
gradingStrategy
;
}
}
void
setState
(
String
state
)
{
boolean
isFullTime
(
)
{
this
.
state
=
state
.
toUpperCase
()
;
return
credits
>=
Student
.
CREDITS_REQUIRED_FOR_FULL_TIME
;
}
}
void
addGrade
(
Grade
grade
)
{
boolean
isInState
(
)
{
grades
.
add
(
grade
);
return
state
.
equals
(
Student
.
IN_STATE
);
}
}
double
getGpa
()
{
double
getGpa
()
{
...
@@ -69,7 +85,23 @@ class Student {
...
@@ -69,7 +85,23 @@ class Student {
return
total
/
grades
.
size
();
return
total
/
grades
.
size
();
}
}
void
setGradingStrategy
(
HonorsGradingStrategy
gradingStrategy
)
{
int
getCredits
()
{
this
.
gradingStrategy
=
gradingStrategy
;
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
;
package
com
.
example
.
paktalin
.
agilejava
;
import
com.example.paktalin.agilejava.language_tests.LanguageTests
;
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.language_tests.SuperClassTest
;
import
com.example.paktalin.agilejava.summer.SummerCourseSession
;
import
com.example.paktalin.agilejava.summer.SummerCourseSession
;
...
@@ -28,6 +29,7 @@ public class AllTests extends TestSuite {
...
@@ -28,6 +29,7 @@ public class AllTests extends TestSuite {
suite
.
addTestSuite
(
LanguageTests
.
class
);
suite
.
addTestSuite
(
LanguageTests
.
class
);
suite
.
addTestSuite
(
SuperClassTest
.
class
);
suite
.
addTestSuite
(
SuperClassTest
.
class
);
suite
.
addTestSuite
(
LoopTest
.
class
);
return
suite
;
return
suite
;
}
}
}
}
app/src/test/java/com/example/paktalin/agilejava/StudentTest.java
View file @
58c4f184
...
@@ -10,13 +10,15 @@ import junit.framework.TestCase;
...
@@ -10,13 +10,15 @@ import junit.framework.TestCase;
public
class
StudentTest
extends
TestCase
{
public
class
StudentTest
extends
TestCase
{
public
void
testCreate
()
{
public
void
testCreate
()
{
final
String
firstStudentName
=
"Jane Doe"
;
Student
student
=
new
Student
(
"Jane Doe"
);
Student
student
=
new
Student
(
firstStudentName
);
verifyNamesCorrect
(
student
,
"Jane Doe"
,
"Jane"
,
"Doe"
,
""
);
assertEquals
(
firstStudentName
,
student
.
getName
());
final
String
secondStudentName
=
"Joe Blow"
;
student
=
new
Student
(
"Blow"
);
Student
secondStudent
=
new
Student
(
secondStudentName
);
verifyNamesCorrect
(
student
,
"Blow"
,
""
,
"Blow"
,
""
);
assertEquals
(
secondStudentName
,
secondStudent
.
getName
());
student
=
new
Student
(
"Raymond Douglas Davies"
);
verifyNamesCorrect
(
student
,
"Raymond Douglas Davies"
,
"Raymond"
,
"Davies"
,
"Douglas"
);
}
}
public
void
testStudentStatus
()
{
public
void
testStudentStatus
()
{
...
@@ -88,4 +90,12 @@ public class StudentTest extends TestCase {
...
@@ -88,4 +90,12 @@ public class StudentTest extends TestCase {
student
.
setGradingStrategy
(
new
HonorsGradingStrategy
());
student
.
setGradingStrategy
(
new
HonorsGradingStrategy
());
return
student
;
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