language: JAVA
the Problem
Below are a series of problems you need to solve using recursive methods. You will write a program that will read commands from an input file, with each command referring to one of the recursive problems to be executed. Each command will be followed (on the same line of input) by the respective parameters required for that problem. (15 points for main method)
Write a recursive method that checks whether an array of integers - given as parameter - is sorted in descending order or not.
The result must be 0 if the array is not sorted or if it is sorted in ascending order. 1 if the array is sorted in descending order.
In the main program you need to transform a series of positive integers separated by ';' into an array of integers and pass it as a parameter of this method. This part does not use recursion to transform the string into an array.
Example1:
Command: DescArrayCheck 112;104;52;32;12;10
Result: 1 (Sorted array in descending order).
Example2:
Command: DescArrayCheck 12;14;52;132;212
Result: 0 (Sorted array in ascending order).
Example3:
Command: DescArrayCheck 52;13;21;3
Result: 0 (Unsorted array).
Example4:
Command: DescArrayCheck 14
Result: 1 (Sorted array in descending order).
Write a recursive method that receives a decimal number and converts it to a hexadecimal number. The decimal to hexadecimal conversion can be performed by applying the repeated division and remainder algorithm.
Example1:
Command: DecToHex 4253
Result: 109D
Example2:
Command: DecToHex 314
Result: 13A
Given a string, a substring, and a number as parameters, write a recursive method that calculates recursively if at least n occurrences of a sub-string exist in string.
Example1:
Command: Noccurrences ababababb bab 2
Result: true (number of occurrence is 3)
Example2:
Command: Noccurrences 2121221222 212 5
Result: false (number of occurrence is 3)
Example3:
Command: Noccurrences yyyyyy yyy 3
Result: true (number of occurrence is 4)
Input File Specifications
You will read in input from a file, "input.in.txt". Have this AUTOMATED. Do not ask the user to the name of the input file. You should read in this automatically. The first line of the input file will have one positive integer, representing the number of commands (lines) inside the input file.
Each of the following n lines will have a command, and each command will be followed by appropriate data as described below (and this data will be on the same line as the command).
The commands (for the 3 recursive methods), and their relevant data, are described below:
DescArrayCheck: This command will be followed by a series of integers separated by ';'.
DecToHex This command will be followed by a single decimal number.
Noccurrences This command will be followed by a string str, a substring subStr and a positive number N representing the number of occurrences of Substr in Str.
input file:
9
DescArrayCheck 112;104;52;32;12;10
DescArrayCheck 12;14;52;132;212
DescArrayCheck 52;13;21;3
DescArrayCheck 14
DecToHex 4253
DecToHex 314
Noccurrences ababababb bab 2
Noccurrences 2121221222 212 5
Noccurrences yyyyyy yyy 3
ouput file:
DescArrayCheck 112;104;52;32;12;10
Result: 1 (Array elements are sorted in descending order)
DescArrayCheck 12;14;52;132;212
Result: 0 (Array elements are not sorted in descending order)
DescArrayCheck 52;13;21;3
Result: 0 (Array elements are not sorted in descending order)
DescArrayCheck 14
Result: 1 (Array elements are sorted in descending order)
DecToHex 4253 (Decimal)
Result: 109D (Hexadecimal)
DecToHex 314 (Decimal)
Result: 13A (Hexadecimal)
Noccurrences ababababb bab 2
Result: true ("ababababb" contains more than 2 occurrences of
"bab")
Noccurrences 2121221222 212 5
Result: false ("2121221222" contains less than 5 occurrences of
"212")
Noccurrences yyyyyy yyy 3
Result: true ("yyyyyy" contains more than 3 occurrences of
"yyy")
i have filled the array in the code itself. if you want to take input from the user, do comment back. i will provide that as well.
also, if you understood the concept, please like the answer.
Get Answers For Free
Most questions answered within 1 hours.