Commit 7771f3c3 authored by Valipi's avatar Valipi

hope this works

parent 31659c26
public class AssessmentPartOne {
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 && num1 < num3) { // if num 1 is smaller than num 2 & num 3, num 2 or 3 must be the bigger one
if (num2 > num3) {
return num2;
}
else {
return num3;
}
}
return num1; // otherwise we return 1
}
public int sumNumbersBetween(int start, int end)
{
int sumOfSquares = 0;
if (start <= 0 || end <= 0 || start > end || start + 1 == end ) { // makes sure it does the thing right
return -1;
}
for (int i = start + 1; i < end; i++ ) {
sumOfSquares += i;
}
return sumOfSquares;
}
}
public class AssessmentPartTwo {
public int scrabbleScore(String aWord)
{
String workedWord = aWord.toLowerCase(); // to ensure that there's no upper case tomfoolery
int holder = 0;
for (int i = 0; i < aWord.length(); i++) { // go through each letter, give them points. The case statement
switch (workedWord.charAt(i)) { // means each individual character is valued.
case 'e':
holder+= 1;
break;
case 'a':
holder+= 1;
break;
case 'i':
holder+= 1;
break;
case 'o':
holder+= 1;
break;
case 'n':
holder+= 1;
break;
case 'r':
holder+= 1;
break;
case 't':
holder+= 1;
break;
case 'l':
holder+= 1;
break;
case 's':
holder+= 1;
break;
case 'u':
holder+= 1;
break;
case 'd':
holder+= 2;
break;
case 'G':
holder+= 2;
break;
case 'b':
holder+= 3;
break;
case 'c':
holder+= 3;
break;
case 'm':
holder+= 3;
break;
case 'p':
holder+= 3;
break;
case 'f':
holder+= 4;
break;
case 'h':
holder+= 4;
break;
case 'v':
holder+= 4;
break;
case 'w':
holder+= 4;
break;
case 'y':
holder+= 4;
break;
case 'k':
holder+= 5;
break;
case 'j':
holder+= 8;
break;
case 'x':
holder+= 8;
break;
case 'q':
holder+= 10;
break;
case 'z':
holder+= 10;
break; // goes through each word, ascribes them a point equal to their value, goes through the next word
}
}
return holder;
}
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'
int numCount = 0;
int characterCount = 0;
int lowerCount = 0;
if (password.contains("password") || password.contains("passwd") ) { // if at any point it contains thta
return false;
}
if (password.length() >= 8 && password.length() <= 16 ) // checking for size
{ //ensuring that it's not password
for (int i = 0; i < password.length(); i++) {
if (password.charAt(i) == '1' || password.charAt(i) == '2' || password.charAt(i) == '3' ||
password.charAt(i) == '4' || password.charAt(i) == '5' || password.charAt(i) == '6' ||
password.charAt(i) == '9' || password.charAt(i) == '8' || password.charAt(i) == '7' ||
password.charAt(i) == '0') { //makes sure that it has a number
numCount += 1;
}
if (Character.isUpperCase(password.charAt(i))) { // checks for an uppercase letter
characterCount += 1;
}
if (Character.isLowerCase(password.charAt(i))) { // and a lower one for validity
lowerCount += 1;
}
}
if (characterCount >= 1 && numCount >= 1 && lowerCount >= 1) {
return true;
}
}
return false;
}
}
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 fuck = 0;
if (!Character.isAlphabetic(theChar)) {
return theChar;
}
char holder = (char)(theChar + theOffset);
if (Character.toLowerCase(holder) > 'z') {
return (char)(theChar - (26-theOffset)); // if it goes off the end, make sure it doesn't
}
if (Character.toLowerCase(holder) < 'a') {
return (char)(theChar + (theOffset + 26 )); // if it goes before, make sure it doesn't
}
return holder;
}
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 response = "";
char holder;
for (int i = 0; i < theMessage.length(); i++) {
holder = theMessage.charAt(i);
response += enryptedCharacter(holder, theOffset); // call the method with its typo
}
return response;
}
}
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