Question: I just completed this code but i can not make it run, It compiles well but when I run it i get an error please

I just completed this code but i can not make it run, It compiles well but when I run it i get an error please HELP!

import java.util.Scanner;

import java.lang.*;

public class ExerciseFunctions

{

/**

Boolean function returns true if the given string begins with "win",

except the 'w' can be anything, so "win", "fin", "pin", "8in" .. all count.

winCondition("win prizes") true

winCondition("pin the tail") true

winCondition("wit fries?") false

winCondition("pit viper") false

*/

public static boolean winCondition(String original)

{

boolean returnValue = false;

if(original.startsWith("in ",1))

returnValue = true;

return returnValue;

}

/**

@return the largest of three given int values.

maxInt(1, 2, 3) 3

maxInt(3, 2, 3) 3

maxInt(2, 5, 3) 5

maxInt(7, 5, 4) 7

*/

public static int maxInt(int first, int second, int third)

{

int returnValue = 0;

if ( first > second && first > third )

returnValue = first;

else if ( second > first && second > third )

returnValue = second;

else if ( third > first && third > second )

returnValue = third;

else

returnValue=-1;

return returnValue;

}

/**

@return true only if both input strings are "naughty".

isNaughty("naughty", "naughty") true

isNaughty("naughty", "any-string") false

isNaughty("any-string", "naughty") false

isNaughty("any-string", "any-string") false

*/

public static boolean isNaughty(String firstString, String secondString)

{

boolean returnValue = false;

if(firstString.equals("naughty") && secondString.equals("naughty")) returnValue=true;

return returnValue;

}

/**

@return true if either input string is "nice".

isNice("nice", "any-string") true

isNice("any-string", "nice") true

isNice("nice", "any-string") true

isNice("any-string", "any-string") false

*/

public static boolean isNice(String firstString, String secondString)

{

boolean returnValue = false;

int flag1 = 1;

int flag2 = 1;

flag1 = firstString.compareTo("nice");

flag2 = secondString.compareTo( "nice" );

if(flag1 == 0 || flag2 == 0)

returnValue = true;

return returnValue;

}

/**

@return of two int values, whichever is closer to ten.

In the event of a tie return 0.

Note that Math.abs(n) returns the absolute value of a number.

nearest10(8, 13) 8

nearest10(13, 8) 8

nearest10(13, 7) 0

*/

public static int nearest10(int firstNumber, int secondNumber)

{

int returnValue = 0;

int diff1=Math.abs(firstNumber-10);

int diff2=Math.abs(secondNumber-10);

if(diff1>diff2) returnValue=secondNumber;

else if(diff2>diff1) returnValue=firstNumber;

else returnValue=0;

return returnValue;

}

/**

Boolean function takes two non-negative int values as input.

@return true if they have the same last digit, such as with 27 and 57.

Note that the % "mod" operator computes remainders, so 27 % 10 is 7.

sameLastDigit(3, 3) true

sameLastDigit(7, 17) true

sameLastDigit(6, 17) false

sameLastDigit(3, 113) true

*/

public static boolean sameLastDigit(int firstNumber, int secondNumber)

{

boolean returnValue = false;

if(firstNumber > 10)

firstNumber = Math.abs(firstNumber % 10);

if(secondNumber > 10)

secondNumber = Math.abs(secondNumber % 10);

if(secondNumber == firstNumber)

returnValue = true;

return returnValue;

}

/**

@return given a string of the form I love any-thing" returns "any-thing loves you"

if the input is not of the form "I love any-thing" the function

returns the string "Fred Rogers 143"

lovesYou("I love TAMU") "TAMU loves you"

lovesYou("I love Basketball") "Basketball loves you"

lovesYou("") "Fred Rogers 143"

lovesYou("any thing else") "Fred Rogers 143"

*/

public static String lovesYou(String original)

{

String returnValue = "";

String[] temp=original.split(" ");

if(temp.length<3) returnValue="Fred Rogers 143";

else if(temp[0].equals("I") && temp[1].equals("love")) returnValue=temp[2]+" loves you";

else returnValue="Fred Rogers 143";

return returnValue;

}

/**

@return Given a String, removes the characters 22 if they occur.

If 22 occurs at the end or beginning of the input String remove any whitespace

that occurs at the beginning or end of the String.

catch22("Catch 22") "Catch"

catch22("22 Rifle") "Rifle"

catch22("Bottles of beer, 22 on the Wall") "Bottles of beer, on the Wall"

** Note this function does not need to remove whitespace inside the string

**Beer example output contains 2 spaces resulting when 22 was removed **

*/

public static String catch22(String original)

{

String returnValue = "";

returnValue=original.replace("22", " ");

return returnValue.trim();

}

/**

@return given a String, that String with the first character of each input word capitalized.

formalWords("hi") "Hi"

formalWords("This is our finest hour") "This Is Our Finest Hour"

*/

public static String formalWords(String original)

{

String returnValue = "";

String[] temp=original.split(" ");

for(String s:temp){

String cap= s.substring(0, 1).toUpperCase() + s.substring(1);

returnValue+=cap+" ";

}

return returnValue.trim();

}

/**

@return given an input String, that String with all English articles (the, an, a) removed.

deleteArticles("cat") "cat"

deleteArticles("a cat") "cat"

deleteArticles("The cat in a hat") "cat in hat"

** Note more strict whitespace removal required in this function **

You can assume that replacing double-spaces with single-spaces is always OK.

*/

public static String deleteArticles(String original)

{

String returnValue = "";

original = original.replaceAll("the ","");

original = original.replaceAll("an ","");

original = original.replaceAll("a ","");

returnValue = original.trim();

return returnValue;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!