Question
The promptAndRemoveVowelish method takes a Scanner as input. It should prompt the user to enter a line and then report back what that line would
The promptAndRemoveVowelish method takes a Scanner as input. It should prompt the user to enter a line and then report back what that line would be with the \"vowelish\" characters removed. The \"vowelish\" characters are defined in the method \"isVowelish\". The method should repeatedly prompt the user for strings until they enter an empty line, when the method should print \"Goodbye!\" and then end. For full credit this method MUST make use of the disemvowel method that is above it in the code. Here is a sample transcript of how this method should work when called - remember that user inputs are in bold:
Enter a line: Testing A Line
Disemvoweled: Tstng A Ln
Enter a line: ALL CAPS
Disemvoweled: ALL CAPS
Enter a line:
Goodbye!
The promptForNames method takes a Scanner as input. It should prompt the user for a number of names to enter, and then prompt the user for those names one at a time, storing them in an array. The method should return the array to the calling program. Here is a sample transcript of how this method should work when called - remember that user inputs are in bold: Names to store: 3
Name: Charlie Brown
Name: Lucy van Pelt
Name: Peppermint Patty
After these inputs, the method would return the array [ \"Charlie Brown\", \"Lucy van Pelt\", \"Peppermint Patty\" ] to the calling method. If you have written your methods correctly, running your program with the default main method should produce the following output (as always, user inputs are in BOLD)
import java.util.Arrays; import java.util.Scanner; public class VariousMethods { /** * Returns true if the parameter c is a \"vowelish\" character, which * is defined to be a lowercase 'a', 'e', 'i', 'o', or 'u'. Otherwise * returns false. * * @param c character to check for \"vowelish\"-ness * @return true if c is lowercase 'a','e','i','o','u', false otherwise */ public static boolean isVowelish(char c) { // TODO: Implement this method // TODO: remove the following line before completing // this line is only here to allow the template // to compile. return false; } /** * Returns a new String that is a copy of the parameter str with * the \"vowelish\" characters as defined above removed. For example, * if str = \"349 Nosuch Ave\" this method would return \"349 Nsch Av\". * For full credit this methods MUST make use of the isVowelish * method above. * * @param str the String to remove vowelish characters from * @return a new copy of str with the vowelish characters removed */ public static String disemvowel(String str) { // TODO: Implement this method // TODO: remove the following line before completing // this line is only here to allow the template // to compile. return \"\"; } /** * See the exam write-up for details on this method. * @param input a Scanner to read input from. */ public static void promptAndRemoveVowelish(Scanner input) { // TODO: Implement this method } /** * Returns a new array that has the same contents as the * parameter arr but in reverse order. For example, if * arr = {\"abc\", \"def\", \"ghi\"}, then this method will * return a new array containing {\"ghi\", \"def\", \"abc\"}. * The original array arr should be unchanged. YOU MAY * NOT USE ANY BUILT-IN REVERSE METHODS IN YOUR * IMPLEMENTATION. * * @param array the array to reverse. * @return a new array that is the reverse of the array arr */ public static String[] reverseArray(String[] arr) { // TODO: Implement this method return new String[0]; } /** * Modifies the parameter arr in place so that every String * in the array is of length len. Strings that are too long * get truncated, Strings that are too short are padded with * '_' characters. For example, if arr = {\"Now\", \"have\", \"a\", * \"test\" } and len = 3, then arr should be modified to be * {\"Now\", \"hav\", \"a__\", \"tes\"}. * * @param arr array holding original String values * @param len length to set Strings in arr to */ public static void setLengths(String[] arr, int len) { // TODO: Implement this method } /** * See the exam write-up for details on this method * @param input a Scanner to read input from * @return an array of Strings. */ public static String[] promptForNames(Scanner input) { // TODO: Implement this method // TODO: remove the following line before completing // this line is only here to allow the template // to compile. return new String[0]; } // NOTE: DO NOT CHANGE ANYTHING IN THIS METHOD! // This method will produce the output that // zyBooks is looking for for some of its automated // tests. public static void runTests(Scanner input) { System.out.println(\"Is 'a' vowelish? \"+isVowelish('a')); System.out.println(\"Is 'A' vowlish? \"+isVowelish('A')); System.out.println(\"Is 'x' vowelish? \"+isVowelish('x')); System.out.println(\"Is 'Z' vowelish? \"+isVowelish('Z')); System.out.println(disemvowel(\"349 Nosuch Ave\")); System.out.println(disemvowel(\"123 Fake Street\")); System.out.println(disemvowel(\"THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG\")); System.out.println(disemvowel(\"the quick brown fox jumps over the lazy dog\")); String[] array = {\"Bob\", \"Mary\", \"Carol\", \"Fred\"}; System.out.println(Arrays.toString(reverseArray(array))); setLengths(array,5); System.out.println(Arrays.toString(array)); promptAndRemoveVowelish(input); String[] names = promptForNames(input); System.out.println(Arrays.toString(names)); System.out.println(\"Reversing array of names:\"); System.out.println(Arrays.toString(reverseArray(names))); } // NOTE: You may comment out the call to runTests // and enter your own main code. However before // making your final submission make sure you // have put this method back to how it started! public static void main(String[] args) { //Set up the Scanner Scanner keyboard = new Scanner(System.in); // Call runTests (comment this out to create your own small tests, // but uncomment it and remove your tests before submitting) runTests(keyboard); // Close the Scanner. keyboard.close(); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started