Commit dc557b77 authored by tomun's avatar tomun

Merge remote-tracking branch 'origin/master'

parents 3feac6bd f47ba0c4
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Assessment02-18</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
public class AssessmentPartThree {
// The simplest form of encryption is the rotation cipher (also known as Caeser's Cipher)
// An offset value is chosen to encrypt a message. Each letter is replaced by the
// letter that that number of places away from it.
// So if an offset value of 1 is chosen, each letter is replaced by the one after it
// - so a becomes b, b becomes c, etc
// If a value of -2 is chosen a becomes y, b becomes z and so on
public char enryptedCharacter(char theChar, int theOffSet)
{
// 05 - encryptedCharacter
// Complete this method so that it returns the encrypted character for
// theChar when and offset of theOffset is used
// So if theChar='m' and theOffset is 3 the method will return 'p'
// Lower case characters remain lower case, upper case remain upper case
// Any other characters are returned unchanged
int charNum = (int) theChar;
if((65 <= charNum && charNum <= 90))
{
if(theOffSet >0) {
for(int i = theOffSet; i !=0; i--)
{
charNum = charNum +1;
if(charNum >90)
{
charNum = 65;
}
}
theChar = (char)charNum;
return theChar;
}
else
{
for(int i = theOffSet; i !=0; i++)
{
charNum = charNum -1;
if(charNum < 65)
{
charNum = 90;
}
}
theChar = (char)charNum;
return theChar;
}
}
else if(97 <= charNum && charNum <= 122)
{
if(theOffSet >0) {
for(int i = theOffSet; i !=0; i--)
{
charNum = charNum +1;
if(charNum >122)
{
charNum = 97;
}
}
theChar = (char)charNum;
return theChar;
}
else
{
for(int i = theOffSet; i !=0; i++)
{
charNum = charNum -1;
if(charNum < 97)
{
charNum = 122;
}
}
theChar = (char)charNum;
return theChar;
}
}
else
{
return theChar;
}
}
public String encryptedString(String theMessage, int theOffSet)
{
// 06 - encryptedMessage
// Complete this method so that it uses encryptedCharacter to
// return the encrypted version of theMessage using theOffset
String encryptedMessage = "";
for(int i = 0; i < theMessage.length(); i++)
{
encryptedMessage += enryptedCharacter(theMessage.charAt(i), theOffSet);
}
return encryptedMessage;
}
}
public class assessment {
public int biggestOfThree(int num1, int num2, int num3)
{
// 01 - A Gentle Start
// Debug this method so it passes the unit test.
// Add comments beside any changes you make
if (num1>num2)//change symbol around.
{
if (num3>num1)
{
return num3;
}
else
{
return num1;
}
}
else
{
if (num3>num2)
{
return num3;
}
else
{
return num2; //added ; syntax error
}
}
}
public int sumNumbersBetween(int start, int end)
{
// 02 - Adding Across A Range
// Complete this method so that it adds together all
// the integers between start and end, but not including
// start or end
// This method should only deal with 0 and positive integers
// This method should return -1 if it cannot calculate the result
// You should comment your code explaining what each part does
int sumOfSquares = 0;
if(start < 0 || end < 0 || ((end - start) <= 1))
{
for(int i = start +1;i < end; i++)
{
sumOfSquares += i;
}
}
else
{
return -1;
}
return sumOfSquares;
}
}
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.
int score = 0;
int [] charScores = {1,3,3,2,1,4,2,4,1,8,5,1,3,1,1,3,10,1,1,1,1,4,4,8,4,10};
for(int i = 0; i < aWord.length(); i++)
{
int pos = Character.toUpperCase(aWord.charAt(i))-65;
score += charScores[pos];
}
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 valid = false;
Boolean upperLetter = false;
Boolean lowwerLetter = false;
Boolean number = false;
if ( password.toLowerCase().indexOf("passwd") != -1 | password.toLowerCase().indexOf("password") != -1)
{
return false;
}
if(password.length() > 7 && password.length() < 17)
{
for(int i = 0; i < password.length();i++)
{
if(password.charAt(i) <= 90 && password.charAt(i) >= 65)
{
upperLetter = true;
}
if(password.charAt(i) <= 122 && password.charAt(i) >= 97)
{
lowwerLetter = true;
}
if(password.charAt(i) <= 57 && password.charAt(i) >= 48)
{
number = true;
}
if(upperLetter && lowwerLetter && number)
{
return true;
}
}
}
return false;
}
}
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));
}
}
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