Homework-Strings

docx

School

Cincinnati State Technical and Community College *

*We aren’t endorsed by this school

Course

101

Subject

Computer Science

Date

Apr 3, 2024

Type

docx

Pages

2

Uploaded by ChiefKangarooPerson772

Report
01540d62785eac788b038188460aba1eec480fe9.docx March 25, 2024 Page 1 of 2 IT-161 Java Programming #1 Homework: Strings Reading(s) : Strings You cannot use any built-in string functions for the following problems except length() and charAt(). For procedures that take an index and/or length be sure to have boundary checking and test with bad values (e.g. negative or too long). Clip values that are outside the valid range. (25%). Be sure to use proper JavaDoc (begins with /**) comments/documentation above your class and method definitions. The methods must be the same names as referenced in this document. (25%) In one program called CHomework6## (where ## is your initials): 1. Write a method that takes a string as a parameter/argument. The function should count all the vowels (A, E, I, O, U) in the string and return the total. Count both uppercase and lowercase vowels. Call this function from main and print the total in main. For example: // Problem #1 – Count Vowels intVowelCount = CountVowelsInString( "I Love Java" ); // Should return 5 System.out.println( "Vowel Count = " + intVowelCount ); 2. Write a method that takes a string and a character as parameters/arguments. The function should return the index of the first occurrence of the character in the string. Check both uppercase and lowercase letters. Call this function from main and print the index in main. Return -1 if the letter is not in the string. For example: // Problem #2 – Find Letter intLetterIndex = FindLetterInString( "I Love Java ", 'J' ); // Should return 7: index of first J System.out.println( "Letter index = " + intLetterIndex ); 3. Write a method that takes a string and a character as parameters/arguments. The function should count how many times the character appears in the string and return the total. Count both uppercase and lowercase letters. Call this function from main and print the total in main. For example: // Problem #3 – Count Letter intLetterCount = CountLetterInString( "I Love Java", 'A' ); // Should return 2 System.out.println( "Letter Count = " + intLetterCount ); 4. Write a method that takes a string and an integer as parameters/arguments: strSource, intLength. The function should return a substring from strSource of length intLength starting at the left of the string. Be sure to boundary check intLength. For example: // Problem #4 – Left strBuffer = Left( "I Love Java", 3 ); // Should return “I L” System.out.println( "Left(3) = " + strBuffer ); 5. Write a method that takes a string and an integer as parameters/arguments: strSource, intLength. The function should return a substring from strSource of length intLength starting at the right of the string. Be sure to boundary check intLength. For example // Problem #5 – Right strBuffer = Right( "I Love Java", 3 ); // Should return “ava” System.out.println( "Right(3) = " + strBuffer ); 6. Write a method that takes a string and two integers as parameters/arguments: strSource, intStartIndex, intLength. The function should return a VB substring from strSource of length intLength starting at intStartIndex. Be sure to boundary check intStartIndex and intLength. For example: // Problem #6 – VB SubString
01540d62785eac788b038188460aba1eec480fe9.docx March 25, 2024 Page 2 of 2 strBuffer = VBSubString ( "I Love Java", 2, 4 ); // Should return “Love” System.out.println( "VB SubString = " + strBuffer ); 7. Write a method that takes a string and two integers as parameters/arguments: strSource, intStartIndex, intStopIndex. The function should return a Java substring from strSource starting at intStartIndex and going up to but not including intStopIndex. Be sure to boundary check intStartIndex and intStopIndex. For example: // Problem #7 – Java SubString strBuffer = JavaSubString ( "I Love Java", 2, 6 ); // Should return “Love” System.out.println( "Java SubString = " + strBuffer ); 8. Write a method that takes a two strings parameters/arguments: strLeft, strRight. The function should compare the two strings and return true if they are the same and false if they are different. For example: // Problem #8 – Java Compare String strSource = “I Love Java”; if( CompareStrings( strSource, new String( “I Love Java” ) ) == true ) // Should return true { System.out.println( "Same” ); } else { System.out.println( "Different” ); } 9. Write a method that takes a string as a parameter/argument. The function should count how many words are in the string and return the total. Counting spaces is NOT the same thing as counting words. Call this function from main and print the total in main. This is a tough one. For example: // Problem #9 – Count Words intWordCount = CountWordsInString( " I Love Java Class " ); // Should return 4 System.out.println( "Word Count = " + intWordCount );
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help