Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Ash Brett Assessment Part two
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
ash.brett
Ash Brett Assessment Part two
Commits
8ad0a751
Commit
8ad0a751
authored
Jan 08, 2019
by
ash.brett
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update AssessmentPartTwo.java
parent
a607aa3a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
172 additions
and
173 deletions
+172
-173
AssessmentPartTwo.java
src/AssessmentPartTwo.java
+172
-173
No files found.
src/AssessmentPartTwo.java
View file @
8ad0a751
public
class
AssessmentPartTwo
{
public
int
scrabbleScore
(
String
aWord
)
...
...
@@ -14,20 +13,20 @@ public class AssessmentPartTwo {
// 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.
//Setting up the Primitive int data type of
sumOfNumbers and setting it's value to 0
//Setting up the Primitive int data type of
wordScore and setting it's value to 0
int
wordScore
=
0
;
//Setting Up the int data type variable I to equal 0.
//And stating that for each time i is is less than the string aWord's length length it will convert aWord to lowercase
//Setting Up the int data type variable i to equal 0.
//And stating that for each time i is less than the string aWord's length it will convert aWord to lowercase
for
(
int
i
=
0
;
i
<
aWord
.
length
();
i
++)
{
aWord
=
aWord
.
toLowerCase
();
//The Program then creates the primitive data type char called letterScore and then sets it to equal the char at the position of i in aWord
// I's position is determined by what it equal to on this run through the code
char
letter
Score
=
aWord
.
charAt
(
i
);
//The Program then creates the primitive data type char called letterpoints and then sets it to equal the char at the position of i in aWord
// I's position is determined by what it is equal to on this run through the code
char
letter
points
=
aWord
.
charAt
(
i
);
//The switch statement is taking in the char letter
Score and comparing into the case values
switch
(
letter
Score
)
{
//The switch statement is taking in the char letter
points and comparing into the case values
switch
(
letter
points
)
{
case
'a'
:
case
'e'
:
case
'i'
:
...
...
@@ -38,13 +37,13 @@ public class AssessmentPartTwo {
case
's'
:
case
't'
:
case
'u'
:
//If letter
Score is equal to any of the cases above then 1 will be added to the int wordScore
//If letter
points is equal to any of the cases above then 1 will be added to the int wordScore
wordScore
+=
1
;
//The break then stops it from running the next case and resumes the program
break
;
case
'd'
:
case
'g'
:
//If letter
Score is equal to any of the cases above then 2 will be added to the int wordScore
//If letter
points is equal to any of the cases above then 2 will be added to the int wordScore
wordScore
+=
2
;
//The break then stops it from running the next case and resumes the program
break
;
...
...
@@ -52,7 +51,7 @@ public class AssessmentPartTwo {
case
'c'
:
case
'm'
:
case
'p'
:
//If letter
Score is equal to any of the cases above then 3 will be added to the int wordScore
//If letter
points is equal to any of the cases above then 3 will be added to the int wordScore
wordScore
+=
3
;
//The break then stops it from running the next case and resumes the program
break
;
...
...
@@ -61,31 +60,31 @@ public class AssessmentPartTwo {
case
'v'
:
case
'w'
:
case
'y'
:
//If letter
Score is equal to any of the cases above then 4 will be added to the int wordScore
//If letter
points is equal to any of the cases above then 4 will be added to the int wordScore
wordScore
+=
4
;
//The break then stops it from running the next case and resumes the program
break
;
case
'k'
:
//If letter
Score is equal to any of the cases above then 5 will be added to the int wordScore
//If letter
points is equal to any of the cases above then 5 will be added to the int wordScore
wordScore
+=
5
;
//The break then stops it from running the next case and resumes the program
break
;
case
'j'
:
case
'x'
:
//If letter
Score is equal to any of the cases above then 8 will be added to the int wordScore
//If letter
points is equal to any of the cases above then 8 will be added to the int wordScore
wordScore
+=
8
;
//The break then stops it from running the next case and resumes the program
break
;
case
'q'
:
case
'z'
:
//If letter
Score is equal to any of the cases above then 10 will be added to the int wordScore
//If letter
points is equal to any of the cases above then 10 will be added to the int wordScore
wordScore
+=
10
;
//The break then stops it from running the next case and resumes the program
default
:
break
;
}
}
//Once the program has r
an through the code as many times as it needs to it returns the wordScore
//Once the program has r
un through the code as many times as it needs to it returns the wordScore
return
wordScore
;
}
...
...
@@ -98,7 +97,7 @@ public class AssessmentPartTwo {
// 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 !
£$%
// - 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'
...
...
@@ -108,12 +107,12 @@ public class AssessmentPartTwo {
if
(
password
.
length
()
<
8
||
password
.
length
()
>
16
)
{
return
false
;
}
//This section of the code runs if
password is inbetween 8 and 16 characters
//This section of the code runs if
the password is between 8 and 16 characters or is equal to 8 or 16
else
{
//This section of code creates two diffe
nt booleans called UpperCaseCheck and LowerCaseCheck
//Password will be checked to see if it's equal to a it in all lower case if it is the boolean will be set to true
//This section of code creates two diffe
rent booleans called UpperCaseCheck and LowerCaseCheck
//Password will be checked to see if it's equal to it in all lower case if it is the boolean will be set to true
boolean
UppercaseCheck
=
password
.
equals
(
password
.
toLowerCase
());
//Password will be checked to see if it's equal to
a it in all Upper case if it is the boolean will be set to true
//Password will be checked to see if it's equal to
it in all Uppercase if it is the boolean will be set to true
boolean
LowercaseCheck
=
password
.
equals
(
password
.
toUpperCase
());
//Creates a boolean called numCheck and sets it to false.
...
...
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