Question: Need help with Intro to Java Programming problem: To complete the assignment, complete the file called Hw3.java containing the Hw3 class: Write the inputAlphaString method

Need help with Intro to Java Programming problem:

To complete the assignment, complete the file called Hw3.java containing the Hw3 class:

Need help with Intro to Java Programming problem: To complete the assignment,

Write the inputAlphaString method. This method takes a Scanner as a parameter and enters a String consisting only of alphabetic characters (in the English language) from the user using a StringBuilder object. In particular, it should:

Create an empty StringBuilder object.

Repeatedly prompt the user to enter an alphabetic String. An alphabetic String s is one that causes the following expression to be true: s.matches("[a-zA-Z]+"). If the String entered is alphabetic, the method adds it to the StringBuilder object. As soon as a non-alphabetic String is entered, the loop stops. The function returns a String formed from the StringBuilder object. Check the Java API to see StringBuilder methods that are helpful for turning a StringBuilder object into a regular String.

Write the main method. The method creates a Scanner object connected to the keyboard. It prompts the user to enter an integer for the number of Strings to be entered, forcing the user to enter a positive (> 0) value. It creates an array of Strings of the size indicated by the user. The method then uses a for loop to fill the array of Strings using a call to the inputAlphaString method described above. The Scanner from the main method should be passed as a parameter to this method. When the for loop is complete, the main method prints the Strings entered using a call to the printSArray method. Finally, the main method closes the Scanner object.

Debug the printSArray method provided for you. This methods has both compilation and runtime errors, and for the assignment you need to correct the code so that it works. As you make a correction, you must put a comment above the line(s) changed that describes the correction you made. Your comments as well as your corrections will be graded. Also note that you should not change the basic functioning of the method.

The following is some output from my completed solution:

How many strings? -3 Please enter a positive (> 0) number. How many strings? 0 Please enter a positive (> 0) number. How many strings? 3 Enter string #1: Enter an alphabetic string followed by enter: t Enter an alphabetic string followed by enter: e Enter an alphabetic string followed by enter: s Enter an alphabetic string followed by enter: t Enter an alphabetic string followed by enter: % Enter string #2: Enter an alphabetic string followed by enter: one Enter an alphabetic string followed by enter: two Enter an alphabetic string followed by enter: three Enter an alphabetic string followed by enter: four Enter an alphabetic string followed by enter: five Enter an alphabetic string followed by enter: six Enter an alphabetic string followed by enter: & Enter string #3: Enter an alphabetic string followed by enter: good Enter an alphabetic string followed by enter: bye Enter an alphabetic string followed by enter: @ The strings you entered are: test onetwothreefourfivesix goodbye

package hw3; import java util.* public class HW3 Write this method, which should: Create a Scanner object connected to the keyboard Prompt the user to enter an integer for the number of Strings to be entered Create an array of Strings of the size indicated by the user Use a for loop to fill the array of Strings using calls to the inputAlphastring method The Scanner from the main method should be passed as a parameter Print the Strings entered using the printsArray method Close the Scanner public static void main (String args) main method Write this method, which should: Create a StringBuilder object Repeatedly prompt the user to enter an alphabetic string An alphabetic string s is one that would cause the following expression to be true: s matches ("[a-zA-Z]+") If the String entered is alphabetic, add it to the StringBuilder object As soon as an non-alphabetic String is entered the loop stops The function returns a String formed from the StringBuilder object public static String inputAlphaString (Scanner ascan) Replace this stub by a method with the functionality d above return The method below contains compilation and runtime errors which you should: 1. correct and 2. mark so that I can see the changes you've made Do not change the basic functioning of the method just make it run There are four compilation errors and one run-time error public static printsArray (String SArray) for (1 03 1 SArray. length; 1 System. out.print (SArray[i] System. out.println()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!