Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

It\'s highly recommended that you use methods that you\'ve written already to he

ID: 3593920 • Letter: I

Question

It's highly recommended that you use methods that you've written already to help program other methods. For example, it's a very good idea to use your isVowel() in the more complicated methods involving vowels. Similarly, you might consider using your reversed() method in your sameInReverse() method.

The only place where you should print or read input from a Scanner is in main(). Do not print or read input from a Scanner in any other method.

Your main( ) will be used to test your methods. You'll call each of your methods and make sure that they return the desired results. When testing numOccurrences( ), you might write something like:

Explanation / Answer

import java.util.Scanner; public class StringMethods { /* returns true if c is an upper case or lower case vowel * or false otherwise */ public static boolean isVowel(char c) { if(c=='a' ||c=='e' ||c=='i' ||c=='o' ||c=='u' ||c=='A' ||c=='E' ||c=='I' ||c=='O' ||c=='U' ) return true; return false; } /* returns the index of the first vowel in s or -1 * if s contains no vowels */ public static int indexOfFirstVowel(String s) { char chars[] = s.toCharArray(); int i = 0; for (char c : chars) { if (isVowel(c)) return i; i++; } return -1; } /* returns the index of the first occurrence of a vowel * in s starting from index startPosition or -1 if * there are no vowels in s at index startPosition or later */ /* notice that this method has the same name as the previous * one, but that it takes a different number of arguments. * This is perfectly legal in Java. It's called "method overloading" */ public static int indexOfFirstVowel(String s, int startPosition) { char chars[] = s.toCharArray(); for (int i = startPosition-1;i=0;i--) { if (isVowel(chars[i])) return i; } return -1; } /* returns true if the first, last, and middle letter of s is the * same ignoring case or false otherwise. * Returns false if s is shorter than 3 characters * * (Note: when there are an odd number of letters in a word, * for example, the word radar, it's clear what the middle * letter is. What would it mean to be the middle letter * for a word with an even number of letters?) */ public static boolean sameFirstLastMiddle(String s) { int n = s.length(); if(n
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote