Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Assessment1
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
leon.bellerby
Assessment1
Commits
aecf333f
Commit
aecf333f
authored
Jan 07, 2019
by
Leon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Second Commit
parent
e6d08c5b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
215 additions
and
16 deletions
+215
-16
AssessmentPartOne.java
src/AssessmentPartOne.java
+11
-16
AssessmentPartTwo.java
src/AssessmentPartTwo.java
+157
-0
AssessmentPartTwoTest.java
src/AssessmentPartTwoTest.java
+47
-0
No files found.
src/AssessmentPartOne.java
View file @
aecf333f
...
...
@@ -43,29 +43,24 @@ public class AssessmentPartOne {
// You should comment your code explaining what each part does
int
sumOfSquares
=
0
;
int
noSum
=
0
;
int
noSum
=
-
1
;
//if the range descends cancels the sum
int
sum
=
0
;
for
(
int
i
=
start
+
1
;
i
<
end
;
i
++)
{
if
(
i
<
0
)
{
noSum
=-
1
;
}
else
sum
=
sum
+
i
;
for
(
int
i
=
start
+
1
;
i
<
end
;
i
++)
//+1 skips the start value
{
//sum will run between start and end but not include either
sum
=
sum
+
i
;
//adds the numbers up
}
if
(
start
<
0
)
{
sumOfSquares
=
noSum
;
if
(
start
<
0
)
{
sumOfSquares
=
noSum
;
//if the sum starts in the negative cancels it
}
else
if
(
s
um
==
0
)
{
sumOfSquares
=
sum
-
1
;
else
if
(
s
tart
<
end
)
{
sumOfSquares
=
sum
-
1
;
//takes the +1 of the start of the sum if the range decends
}
else
{
sumOfSquares
=
sum
;
else
{
sumOfSquares
=
sum
;
//if the sum is fine returns it
}
System
.
out
.
println
(
sumOfSquares
);
return
sumOfSquares
;
...
...
src/AssessmentPartTwo.java
0 → 100644
View file @
aecf333f
public
class
AssessmentPartTwo
{
public
int
scrabbleScore
(
String
aWord
)
{
// 03 -Scrabble Score
// Complete this method so that it returns the scrabble score for the word in aWord
// In scrabble each letter is worth a number of points and each word is worth the
// sum of the scores of the letters in it. For this assignment we will ignore
// double/treble letter/word bonuses.
// The English language points per letter can be found at
// https://en.wikipedia.org/wiki/Scrabble_letter_distributions
// You will need to come up with a way of connecting each letter to its score and
// a way of identifying each letter in the word.
char
[]
word
=
aWord
.
toCharArray
();
//converts the word into a character array
int
score
=
0
;
//tally of the word score
for
(
int
i
=
0
;
i
<
word
.
length
;
i
++)
{
//goes through every letter of the word until there's no more letters
if
(
word
[
i
]
==
'e'
)
{
//if the letter is present then adds the correct number of points to it
score
=
score
+
1
;
//score
}
if
(
word
[
i
]
==
'a'
)
{
score
=
score
+
1
;
}
if
(
word
[
i
]
==
'o'
)
{
score
=
score
+
1
;
}
if
(
word
[
i
]
==
't'
)
{
score
=
score
+
1
;
}
if
(
word
[
i
]
==
'i'
)
{
score
=
score
+
1
;
}
if
(
word
[
i
]
==
'n'
)
{
score
=
score
+
1
;
}
if
(
word
[
i
]
==
'r'
)
{
score
=
score
+
1
;
}
if
(
word
[
i
]
==
's'
)
{
score
=
score
+
1
;
}
if
(
word
[
i
]
==
'l'
)
{
score
=
score
+
1
;
}
if
(
word
[
i
]
==
'u'
)
{
score
=
score
+
1
;
}
if
(
word
[
i
]
==
'd'
)
{
score
=
score
+
2
;
}
if
(
word
[
i
]
==
'g'
)
{
score
=
score
+
2
;
}
if
(
word
[
i
]
==
'c'
)
{
score
=
score
+
3
;
}
if
(
word
[
i
]
==
'm'
)
{
score
=
score
+
3
;
}
if
(
word
[
i
]
==
'b'
)
{
score
=
score
+
3
;
}
if
(
word
[
i
]
==
'p'
)
{
score
=
score
+
3
;
}
if
(
word
[
i
]
==
'h'
)
{
score
=
score
+
4
;
}
if
(
word
[
i
]
==
'f'
)
{
score
=
score
+
4
;
}
if
(
word
[
i
]
==
'w'
)
{
score
=
score
+
4
;
}
if
(
word
[
i
]
==
'y'
)
{
score
=
score
+
4
;
}
if
(
word
[
i
]
==
'v'
)
{
score
=
score
+
4
;
}
if
(
word
[
i
]
==
'k'
)
{
score
=
score
+
5
;
}
if
(
word
[
i
]
==
'j'
)
{
score
=
score
+
8
;
}
if
(
word
[
i
]
==
'x'
)
{
score
=
score
+
8
;
}
if
(
word
[
i
]
==
'q'
)
{
score
=
score
+
10
;
}
if
(
word
[
i
]
==
'z'
)
{
score
=
score
+
10
;
}
}
return
score
;
}
public
Boolean
passwordValidator
(
String
password
)
{
// 04 - Password Validator
// Complete this method to validate that the String password
// is a valid password
// A password is valid if it is
// - between 8 and 16 characters long (inclusive)
// - made up of letters (upper or lower), numbers, and the following characters !£$%
// - has at least one lower case letter, one upper case letter and a number
// - does not contain the phrases 'password' or 'passwd'
boolean
pass
=
false
;
boolean
hasUppercase
=
!
password
.
equals
(
password
.
toLowerCase
());
boolean
hasLowercase
=
!
password
.
equals
(
password
.
toUpperCase
());
boolean
noConditions
=
!(
password
.
contains
(
"password"
)
||
password
.
contains
(
"passwd"
));
char
[]
pW
=
password
.
toCharArray
();
if
(
pW
.
length
<
8
)
{
pass
=
false
;
}
else
if
(
pW
.
length
>
16
)
{
pass
=
false
;
}
else
if
(!
hasUppercase
)
{
pass
=
false
;
}
else
if
(!
hasLowercase
)
{
pass
=
false
;
}
else
if
(!
noConditions
)
{
pass
=
false
;
}
else
{
pass
=
true
;
}
return
pass
;
}
}
src/AssessmentPartTwoTest.java
0 → 100644
View file @
aecf333f
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
import
org.junit.jupiter.api.BeforeAll
;
import
org.junit.jupiter.api.DisplayName
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.params.ParameterizedTest
;
import
org.junit.jupiter.params.provider.CsvSource
;
class
AssessmentPartTwoTest
{
public
static
AssessmentPartTwo
test
;
@BeforeAll
static
void
setUpBeforeClass
()
throws
Exception
{
test
=
new
AssessmentPartTwo
();
}
@ParameterizedTest
@DisplayName
(
"Testing scrabbleScore"
)
@CsvSource
({
"rabbit,10"
,
"speaker,13"
,
"exactly,19"
,
"xylophone,24"
,
"application,17"
})
void
testScrabbleScore
(
String
theWord
,
int
expectedScore
)
{
assertEquals
(
expectedScore
,
test
.
scrabbleScore
(
theWord
));
}
@ParameterizedTest
@DisplayName
(
"Testing passwordValidator"
)
@CsvSource
({
"qw11Ij87,true"
,
"a834j,false"
,
"a88drTcdmn45tdgjhj,false"
,
"pmmfj6793,false"
,
"PASSWORD,false"
,
"lo98passwdiI,false"
,
"oi!Fcv98ij,true"
})
void
testPasswordValidator
(
String
thePassword
,
Boolean
expectedResult
)
{
assertEquals
(
expectedResult
,
test
.
passwordValidator
(
thePassword
));
}
}
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