Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modularity Assignment - Module 5 - Methods App Modularity Assignment Requirements Your Java file named: Methods.java You will write a Java application named, Methods.java, that

Modularity Assignment - Module 5 - Methods App

Modularity Assignment Requirements Your Java file named: Methods.java

You will write a Java application named, Methods.java, that will consist of a main method along with a number of other static methods. Each of these methods is described below, along with the algorithm that should be implemented by the main method. Be sure to use named constants where numeric values are mentioned in the requirements. Follow all coding conventions, including the structured use of if statements and loop statements. Now that you will have multiple methods in one Java class, the required convention of including a prologue before each method must be followed. Method prologues are simply a line or two of comments explaining the purpose of a method, the reason for its parameters, and the content or meaning of the value being returned (if any).

To help you understand the stated requirements that follow, a text file of this program executing (execution log) and the corresponding results written to the output file are available for your perusal and attached to this assignment. Your application must name the output file, MethodsOutput.txt.

Here are the requirements (algorithm!!) for your main method:

Display a message of welcome to the user

Prompt for and get from the user an integer greater than 99

As long as the input integer is not equal to 999 do the following:if the sum of the digits in the input integer is odd do the following:

Prompt for and get from the user a String longer than 2 characters

if the input string is not a palindrome

change the value of the input string to include one underscore between each of the characters in the string

Create a new version of this string that has no vowels

Write to the output file a line containing: the input integer, input string, input string without vowels

[Else] If the sum of the digits in the input integer is even

Write to the output file: the input integer and the sum of the digits in that integer

Prompt for and get from the user another integer greater than 99

Close the output file

Display an application termination message

Here are the details of the methods you MUST write was part of this application. These methods will be called directly by main. Where inside main they are needed (called) will be obvious if you understand what main needs to do and what each of these methods is defined to do. Ask your instructor if this is not clear. If you find a need for any other methods, you should email your instructor about that to see if that makes sense in case you are doing more work than is necessary. All of these methods will be marked as public and static. The return types and the parameters will vary. You must be careful to name the methods exactly as given here, use the exact same return types, AND use the exact same types of parameters in the same order given here. The grader code will assume these method names, return types, and parameter lists are identical for all submissions. Note: the names of parameters can be changed, but NOT their data types or order, nor can new parameters be added, nor can any be removed. If you have questions on this, simply email your instructor your question.

1. Get an integer from the user int getInt(Scanner keyboard) - this method will use an already-created Scanner object passed to it to read an integer from the user. This method will force the user to enter a value greater than 99 by proper use of a while loop. See the example execution log for the text of the prompts and error messages.

2. Get a string from the user String getString(Scanner keyboard) - this method will use an already-created Scanner object passed to it to read a String that contains no spaces from the user. To do this the Scanner's next method will be used. This method will force the user to enter a String whose length is greater than 2 by proper use of a while loop. See the example execution log for the text of the prompts and error messages.

3. Sum the digits in an integer int sumDigits(int val) - this method will sum the digits in the integer value of the input parameter, val. No Strings should be used in this method. The sum of the digits can be calculated using a loop, the remainder operator, addition, and the integer division operator. See the example execution log and the corresponding example output file for values calculated for various integers.

4. Determine if a String is a palindrome boolean isPalindrome( String s ) - this method determines whether the input parameter string is a palindrome and return true if it is and false if it is not a palindrome. A palindrome is a string that is the same character sequence read either backward or forward. The only String class methods that may be used are length and charAt. Use a loop that is able to facilitate comparing the first and last characters, then the second and the second to last, etc. until it finds that the string is or is not a palindrome.

5. Insert one underscore character between each of the characters of a string String insertUnderscores(String s) - this method will create a new String value that has one underscore between each of the characters of the original, input string parameter, s. This newly created String value will then be returned to the caller. There should be no underscore before the first character and no underscore after the last character of this new string value. Use concatenation, the charAt method, and the length method in a loop to build up a new String value that matches these requirements. See the example execution log and the corresponding example output file for values calculated for various Strings.

6. Create a new String value that has none of the vowels (a, e, i, o, u - either case) contained in the input parameter String String devowel(String s) - this method will create a new string that has no vowels but only the other characters that were part of the parameter's string value. Repeated concatenations done within a loop using the charAt method and the length method can accomplish this easily. Vowels are the usual five in either case: Aa, Ee, Ii, Oo, Uu. See the example execution log and the corresponding example output file for values calculated for various Strings.

7. Write to the output file void writeToOutputFile( PrintWriter outFile, int input, String inStr, String devoweled ) This method is passed an already created PrintWriter object which it uses to output the input integer value, the input String value, and the de-voweled version of the input String value. See the example execution log and the corresponding example output file for the format and text of labels used for the output.

8. Write to the output file (a second, overloaded output method) void writeToOutputFile( PrintWriter outFile, int input, int digitSum ) This method is passed an already created PrintWriter object which it uses to output the input integer value, and the sum of the digits in this integer. See the example execution log and the corresponding example output file for the format and text of labels used for the output. NOTE: overloading is the use of the same method name with the same return type, but a different parameter list. In this case, the two methods that write t the output file are overloaded because they do a similar task, but write different data. This is a good example of the use of overloading.

Note that the Scanner and PrintWriter objects passed to some methods are already created. This implies that they were created with main before the methods needing these objects were called.

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

50 Tips And Tricks For MongoDB Developers Get The Most Out Of Your Database

Authors: Kristina Chodorow

1st Edition

1449304613, 978-1449304614

More Books

Students also viewed these Databases questions

Question

define the term outplacement

Answered: 1 week ago

Question

describe the services that an outplacement consultancy may provide.

Answered: 1 week ago