Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

All of these programs will use recursion. You will NOT use loops for these methods. You'll have one main method that sends the recursive method

All of these programs will use recursion. You will NOT use loops for these methods.

You'll have one main method that sends the recursive method what it needs. The recursive method will return the results to the main.

You will print the results to the terminal window and to an output file (except for Program 4).

All input for this program will be stored in input files. You will create an input file for testing each program. Be aware that unknown input files will be used to grade your programs.

Pick 3 of the following 4 programs to implement in Java. If you want extra credit, be sure to pick Program 4. Create a menu and let the user choose the Program to complete. Your menu should have at least 3 items to choose.

Program 1:

pyramid use input file named pyramid.txt

Pyramids will be created from blocks. You'll take the n (number of rows) given to you, your program will then determine the total number of blocks based on how many rows the pyramid has.

Examples:

pyramid where n = 1; returns 1

pyramid where n = 2; returns 3

pyramid where n = 0; returns 0

pyramid where n = 5; returns 15

Program 2 do EITHER option a) or option b):

2a) countSubString use input file named countSubString.txt

Count the number of times the substring sub is included within the string str, no matter what the case (Case is not a factor here.) The string and substring will be stored in an input file on separate lines. Your program will create an output file. Send each pair to the recursive method.

As an example: your input file might contain:

There are Strings and there are strings. How many times is the word 'the' found in this string?

the

Sent to the method: "There are Strings and there are strings. How many times is the word 'the' found in this string?", "the"

Output for countTheSubstrings method

4

2b) stopToGo use input file named stopToGo.txt

Whenever you see the word stop in a string, change it to go. Case is not a factor. For example:

String sent to the method: StoP, I Said Stop!

String returned from the method is: Go, I said Go!

Program 3:

3) countDigits use input file named countDigits.txt

Read in a number and a digit.

Count the number of times you find the digit in the number.

Example:

Sent to the method: 10203040586970 0

Returned the number of times it finds a match: 5

Program 4:

4a) fillArray use input file named fillArray.txt

Read in the number of elements that will be read in.

Create an array of integer values (the number read in will be the max for your array).

Read in that number of integers to fill it with numbers - recursively.

Sent to the method: the empty array

Print your array recursively to the terminal window and to the output file.

Extra Credit- Add to Program 4a above:

4b) (3 points maximum) Request a number from the user (that might be in the array)

Count the number of times you find a match.

Sent to the method: the array and the integer value to match.

Return the number of times it finds a match.

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

More Books

Students also viewed these Databases questions

Question

=+j What rules will apply to the process of negotiations?

Answered: 1 week ago