Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CS 111B Program #4 - Corrected Version Program #4: For this exercise you will write a program that stores strings in an array and

image text in transcribed

CS 111B Program #4 - Corrected Version Program #4: For this exercise you will write a program that stores strings in an array and then "analyzes" these strings. As always, name your program/class Program_4_LastName where LastName is replaced with your last name. The program will perform the following tasks: Ask the user the number of strings to store. Set up an array to hold the strings. Call a method that allows the user to fill the array with strings: Use nextLine() so that strings containing spaces may be entered. Call a method that prints the contents of the string array. Call a method that determines whether the array contains any strings that begin and end with the same character (case specific): If there are any strings that begin and end with the same character, the method will print them. The method will return information to the calling routine (in this case main()) so it can determine if there were any strings that begin and end with the same character; if not, main() will print a "message" stating that no strings begin and end with the same character. Call a method that construct a string in the following manner: Work through the cells of the array from index 0 to the end of the array: If the cell index is odd, add the second character of the string to the string being constructed. If the cell index is even, add the first character of the string to the string being constructed. NOTE: For this method to work, we need to be sure that all strings in cells with an odd index contain at least 2 characters; you can assume the user follows this rule. Return the constructed string to main() where it will be printed: There is no printing in the method. Call a method that uses a Bubble Sort to sort the strings in the array into ascending order lexicographically. After returning from the sort, print the sorted array with an appropriate prompt. Note: Strings entered by the user may contain spaces and may contain characters that are not alphabetical. Runs of the program would look like the following: GRASP exec: java Program_4_Jerkofsky Number of strings: 5 Enter strings: String #1: M String #2: String #3: M two three String #4: four String #5: five one Strings stored: String #1: String #2: two String #3: three String #4: String #5: five four Strings that begin and end with the same character: No strings begin and end with same character. String of characters from each string: extef Sorted array: String #1: String #2: String #3: five four String #4: three String #5:1 two GRASP operation complete. 44 JGRASP exec: java Program_4_Jerkofsky Number of strings: 6 Enter strings: String #1: abcde String #2: badeta M String #3: * * afgketa String #4: jkloo String #5: String #6: XXXXZ Strings stored: String #1: abcde String #2: Badetk String #3: String #4: String #5: ARAHEZ String #6: XXXZ Strings that begin and end with the same character: badetb afgeta String of characters from each string: acakox Sorted array: String #1: String #2: String #3: abcde afabeta badetk String #4: String #5: String #6: XXXZ jklmn GRASP: operation complete.

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

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions