Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please follow the instructions and fill up the code below 2. Lab Requirements You are not allowed to use any regular expressions, loops, or any
please follow the instructions and fill up the code below
2. Lab Requirements You are not allowed to use any regular expressions, loops, or any methods such as "contains", "replace" and so on to solve the problem. In other words, the problem should purely be solved by recursion, and therefore any method that lets you get away from designing a recursive algorithm should be avoided. To practice testing, you are provided with a set of incomplete test cases. You should make sure to add enough test cases that test your code thoroughly. Please have a look at the tester code Lab2Tester and add more test cases to test your code thoroughly. 4.1. Method product0 For this task, we are asking you to implement a recursive method that finds the product of n consecutive integer number, starting from integer start and ends with integer end. For example, if start =1 and end =5, we expect the method to return 120 (i.e. 12345 ). The name of the method is product and the header of the method was written for you in Lab2 .java. 4.2. Method makeString 0 For this task, you are expected to implement a recursive function that creates and returns a string of length n using the given character. For example, if the given character is \#, and n=5, the output should be \#\#\#\#\#. Please note that a string with length zero is also possible. To concatenate to a string, the simple ' + ' operator should be used. The name of the method is makeString and the header of the method was written for you in Lab2.java. 4.3. Method writeChars0 Write a recursive method writeChars that accepts a positive integer n and that returns n characters: The middle character should always be an asterisk ("*"). If you are writing an even number of characters, there will be two asterisks in the middle ("**"). Before the asterisk(s) you should add less-than characters (""). For example, the following calls produce the following output: The name of the method is writeChars and the header of the method was written for you in Lab2, java. 4.4. Method getSubstring0 In this task, you are required to write a recursion that gets a string and two characters and returns the substring that is enclosed in two given characters. You can assume that the given string includes only one instance of each enclosing characters. For example, if the input string is "Hello (there] how are you?" and the first enclosing character is ' C and the second is ']', it should return "there". The name of the method is getSubstring and the header of the method was written for you in Lab2.java. 4.5. Method decimalToBinary0 For this task, you need to write a recursion that converts a positive integer and zero to its binary equivalence. This method gets one integer input. A binary form of an integer is calculated by repeatedly dividing the integer number (and later, its quotient) by 2. You keep doing the division until the quotient is zero. The remainders of the divisions, from the last division to the first, form the binary representation of the integer number. Let's see an example in which 23 is converted to a binary number. R stands for the remainder. 23/2=11R1 11/2=5R1 5/2=2R1 2/2=1R0 1/2=0R1 Therefore, the binary representation of 23 is "10111". The name of the method is decimalToBianry and the header of the method was written for you in Lab2.java. public tinal class Lab2 1 /r* * This is empty by desagn, Lab2 cannot be instantzated */ private Lab2() f \} // empty by design * Returns the product of a consecutive set of numbers from codes start /codes to codes end /codes. * grre. ccodes start \&/codes and (5start+1)+ end *f public static int product(int start, int end) \{ return bs - Sark the integer n shou de bositive public static string vritechars(int a) retum n= ? This nethod returns a subistring of the given input:string that is enclosed in two * given characters. * Cparas open is a character at the beginning of the string that shoeld be returned. - eparan close is a character at the end of the string that should be returned. public static string getsobstring(Scring str, char open, char clowe) f return ine? - after the asteriskis) you shoutd had greater-than characters (ebi). - Ezsran n is the total number of strangs returned by the methed the integer n shoufid be pasitivi BP2xHetnoworder (HethodSorrers.MAME_ASCENDING) puolic clas's Lab2Tcstcr \{ ) erest public void testproduct2() 1 int start =10; int end =10; int prodn 1i: for (int 1= start ;1 cond ;1+4) prod =1; is 3 erest public void testproduct 3()Z int start =10; int end =18; int prod =1; for (int 1=start;1= end ;1+t) prod =1 assertEquais("Failed at product (+start+,"+end+"), prod, Lab2.product ( start, end)); 3 eTest pubtic void testhakestring1() char inte =2e; int n=5 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