Question

language: JAVA the Problem Below are a series of problems you need to solve using recursive...

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)

  1. DescArrayCheck  

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).

  1. DecToHex   

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

  1. Noccurrences   

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")

Homework Answers

Answer #1

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.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
IN JAVA Iterative Linear Search, Recursive Binary Search, and Recursive Selection Sort: <-- (I need the...
IN JAVA Iterative Linear Search, Recursive Binary Search, and Recursive Selection Sort: <-- (I need the code to be written with these) I need Class river, Class CTRiver and Class Driver with comments so I can learn and better understand the code I also need a UML Diagram HELP Please! Class River describes river’s name and its length in miles. It provides accessor methods (getters) for both variables, toString() method that returns String representation of the river, and method isLong()...
JAVA: Design and implement a recursive version of a binary search.  Instead of using a loop to...
JAVA: Design and implement a recursive version of a binary search.  Instead of using a loop to repeatedly check for the target value, use calls to a recursive method to check one value at a time.  If the value is not the target, refine the search space and call the method again.  The name to search for is entered by the user, as is the indexes that define the range of viable candidates can be entered by the user (that are passed to...
IN JAVA!! You may be working with a programming language that has arrays, but not nodes....
IN JAVA!! You may be working with a programming language that has arrays, but not nodes. In this case you will need to save your BST in a two dimensional array. In this lab you will write a program to create a BST modelled as a two-dimensional array. The output from your program will be a two-dimensional array.   THEN: practice creating another array-based BST using integers of your choice. Once you have figured out your algorithm you will be able...
Problem: Certain mathematical problems involve manipulation of the digits within a whole number. One such problem...
Problem: Certain mathematical problems involve manipulation of the digits within a whole number. One such problem requires that the digits be re-arranged.In this project, we will reverse the order of the digits in a number. Assignment: Design, develop, and test an Object-Oriented C++program that reads a whole number from the user, removes the sign and all leading and trailing zeroes from that number, and then performs the following operations on that number: 1) reverses the digits, 2) sorts the digits...
Please answer in JAVA IDS 401 Assignment 4 Deadline In order to receive full credit, this...
Please answer in JAVA IDS 401 Assignment 4 Deadline In order to receive full credit, this assignment must be submitted by the deadline on Blackboard. Submitting your assignment early is recommended, in case problems arise with the submission process. Late submissions will be accepted (but penalized 10pts for each day late) up to one week after the submission deadline. After that, assignments will not be accepted. Assignment The object of this assignment is to construct a mini-banking system that helps...
Task 1: You will modify the add method in the LinkedBag class.Add a second parameter to...
Task 1: You will modify the add method in the LinkedBag class.Add a second parameter to the method header that will be a boolean variable: public boolean add(T newEntry, boolean sorted) The modification to the add method will makeit possible toadd new entriesto the beginning of the list, as it does now, but also to add new entries in sorted order. The sorted parameter if set to false will result in the existing functionality being executed (it will add the...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT