Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/** This exercise involves implementing several methods. Stubs for each method with documentation are given here. It is your task to fill out the code

/** This exercise involves implementing several methods. Stubs for each method with documentation are given here. It is your task to fill out the code in each method body so that it runs correctly according to the documentation.

You should create a main method to run and test your methods. Example inputs with output are provided in the comments before each method. At a minimum, your solutions must pass these tests.

**/

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.length() < 3) { return returnValue; }

if((original.charAt(1) == 'i') && (original.charAt(2) =='n')) { 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 maxValue = Math.max(first, second); maxValue = Math.max(maxValue, third); return maxValue; }

/** @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 returnvalue1 = firstString.equalsIgnoreCase("naughty"); boolean returnvalue2 = secondString.equalsIgnoreCase("naughty");

return returnvalue1 && returnvalue2; }

/** @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; returnValue = firstString.equalsIgnoreCase("nice") || secondString.equalsIgnoreCase("nice"); 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 difference1 = Math.abs(10 - firstNumber); int difference2 = Math.abs(10- secondNumber); if(difference1 == difference2) { return 0; }

return difference1 < difference2 ? firstNumber : secondNumber;

}

/** 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; returnValue = (firstNumber% 10) == (secondNumber% 10);

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 = "";

//Your code here

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 = "";

//Your code here

return returnValue; }

/**

@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 = "";

//Your code here

return returnValue; }

/** @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 = "";

//Your code here

return returnValue; }

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Moving Objects Databases

Authors: Ralf Hartmut Güting, Markus Schneider

1st Edition

0120887991, 978-0120887996

More Books

Students also viewed these Databases questions

Question

=+4 Develop and deliver the CCT program.

Answered: 1 week ago

Question

=+5 Evaluate whether the CCT program was effective.

Answered: 1 week ago

Question

=+Identify the type of global assignment for which CCT is needed.

Answered: 1 week ago