Commit 83770f73 authored by Romain's avatar Romain

part two update

parent 01df26df
Pipeline #378 failed with stages
public class AssessmentPartTwo {
public int scrabbleScore(String aWord)
{
// 03 -Scrabble Score
......@@ -13,7 +13,51 @@ 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.
return 0;
int total = 0;
int point=0;
boolean to=false;
for (int j=0;j<aWord.length();j++)
{
switch(aWord.charAt(j))
{
case 'a': case 'o':case 'e':case 'i':case 'n':case 'r':case 't':case 'l':case 's':case 'u': point=1;
total=total+point;
break;
case 'd':case 'g':point=2;
total=total+point;
break;
case 'b':case 'c':case 'm':case 'p': point=3;
total=total+point;
break;
case 'f':case 'h':case 'v':case 'w':case 'y':point=4;
total=total+point;
break;
case 'k':point=5;
total=total+point;
break;
case 'j':case 'x':point=8;
total=total+point;
break;
case 'q':case 'z':point=10;
total=total+point;
break;
default :
to=true;
break;
}
}
if(to==false)
{
System.out.print(total);
}else
{
System.out.println("Error");
}
return total;
}
......@@ -24,11 +68,79 @@ 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'
boolean pass=false;
boolean valid=false;
boolean lowerCase=false;
boolean upperCase=false;
boolean number=false;
boolean test=false;
boolean specialChar=false;
boolean error=false;
if (password.length()>=8 & password.length()<=16)
{
valid=true;
}
else {
valid=false;
}
for(int i=0;i<password.length();i++)
{
if(Character.isLowerCase(password.charAt(i))==true)
{
lowerCase=true;
}else
{
if(Character.isUpperCase(password.charAt(i))==true)
{
upperCase=true;
}else
{
if(Character.isDigit(password.charAt(i))==true)
{
number=true;
}else
{
switch(password.charAt(i))
{
case '!' : case '%' : case '$': case '£' : test=true;
specialChar=true;
error=false;
break;
default : test=false;
error=true;
break;
}
}
}
}
}
if(password.toLowerCase().contains("password")|password.toLowerCase().contains("passwd"))
{
valid=false;
}
if(lowerCase==true & upperCase==true & valid==true & number==true & error==false)
{
pass=true;
}
else {
pass=false;
}
return false;
return pass;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment