Question
java programing :input 8 eliminateDigit 11712 1 eliminateDigit 332 4 eliminateDigit 666 6 findLargest 32;4;21;-87;3;0;49;143;47 findLargest -32;-4;-21;-87;-3;-43;-7 shuffle abcd efgh shuffle abc fgkl shuffle abcd
java programing
:input
8 eliminateDigit 11712 1 eliminateDigit 332 4 eliminateDigit 666 6 findLargest 32;4;21;-87;3;0;49;143;47 findLargest -32;-4;-21;-87;-3;-43;-7 shuffle abcd efgh shuffle abc fgkl shuffle abcd efg
output :
8 eliminateDigit 11712 1 eliminateDigit 332 4 eliminateDigit 666 6 findLargest 32;4;21;-87;3;0;49;143;47 findLargest -32;-4;-21;-87;-3;-43;-7 shuffle abcd efgh shuffle abc fgkl shuffle abcd efg
Question#1. Given the following code: public static void recSequence(int n) { if (n < 0) throw new IllegalArgumentException(); if (n == 5) { System.out.print("|"); } else { System.out.print("a"); recSequence(n - 1); System.out.print("b"); } } public static void main(String[] args) { recSequence (10); } } a. Consider the above call of the recursive method (recSequence) in the main program, trace the execution of recSequence using the same approach presented in the lectures slides of the Recursion Unit. b. Write the final output of the above method . Question#2. Consider the following output examples for answering the following questions : Example 1: Enter a numerical ascending list and a number to insert: 1256 4 The new list is 12456 Example 2: Enter a numerical ascending list and a number to insert: 1256 8 The new list is 12568 Example 3: Enter a numerical ascending list and a number to insert: 2567 1 The new list is 12567 Example 4: Enter a numerical ascending list and a number to insert: 1356 6 No changes because 6 exist in the list a. Write a main and recursive method called (insertNumber) that inserts a number in a list of ascending numbers and reserves the list order. The insert operation performs if the given number doesnt exist previously in the list. .
b. Trace the execution of insertNumber using example 1 and example 4, which are shown above . Question#3. Consider the attached input and output files for solving the below three problems using recursions. You will write a program that will read a set of commands from the input file and execute the relevant recursive method to get the required output, which is shown in the attached output file. Each command in the input file is followed (on the same line of input) by the respective parameters required for executing the recursive method. [15 points for writing the main method, writing the recursive method for each of the below problems]: Problem#1. Write a recursive method eliminateDigit which accepts a positive integer M (greater than 0) and a digit K and returns an integer number N, such that N is a new number without the K digit occurrences of M. If all M digits are equal to the K digit, then return 0. Consider the following output examples: Example 1: Command: eliminateDigit 11712 1 Output: 72 is the number without digit 1 Example 2: Command: eliminateDigit 332 4 Output: 332 is the number without digit 4 Example 3: Command: eliminateDigit 666 6 Output: 0 is the number without digit 6 Problem#2. Write a recursive method called findLargest that accepts only one parameter which is an array of integer numbers and returns the smallest number in that array. Consider the following output examples: Example 1: Command: findLargest 32;4;21;-87;3;0;49;143;47 Output: The largest number is: 143 Example 2: Command: findLargest -32;-4;-21;-87;-3;-43;-7 Output: The largest number is: -3 Problem#3. Write a recursive method called shuffle that accepts two strings of characters, S1 and S2. The method will return a shuffled string of S1 and S2. The shuffled string will interchange the characters of S1 and S2, respectively. So that the first character of S1 will be followed by the first character of S2, and so on. Consider the following output examples: Example 1: Command: shuffle abcd efgh Output: aebfcgdh is the shuffle of abcd efgh Example 2: Command: shuffle abc fgkl
Output: afbgckl is the shuffle of abc fgkl Example 3: Command: shuffle abcd efg Output: aebfcgd is the shuffle of abcd efg Input File Format and Specifications: You will read the command from the input, called "input.in.txt", which is attached in this assignment. You should open and read this file automatically in the main program without prompting the user to enter the name of the input file. The first line of the input file will contain one positive integer, which represents the number of commands (lines) following that line in the input file. Each of the following n lines in the input file contains a command, which is followed, in the same line, by the required parameters. The commands of the 3 recursive methods, and their required parameters data, are described below: eliminateDigit: This command will be followed by two integers, a and b where b is a one digit number. findLargest: This command will be followed by a set of integers numbers which are separated by ';'. shuffle: This command will be followed by two strings. Output File Format and Specifications: Your program must produce an output file, called "output.out.txt". You must follow the exact format of the output file. Please refer to sample output file for output format and specifications. Grading Details: Your program will be graded upon the following criteria: 1) Adhering to the implementation specifications listed on this write-up. 2) Your algorithmic design. 3) Correctness. 4) Use of Recursion. If your program does not use recursion, you will get a zero. 5) The frequency and utility of the comments in the code, as well as the use of white space for easy readability. (If your code is poorly commented and spaced and works perfectly, you could earn as low as 80-85% on it.) 6) Your program should include a header comment with the following information: your name, email, course number, section number, assignment title, and date. 7) Your output MUST adhere to the EXACT output format shown in the sample output file.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started