Question

Implement the class described by the following API. You do not have to include javadoc comments....

Implement the class described by the following API. You do not have to include javadoc comments.

API - https://www.eecs.yorku.ca/course_archive/2018-19/W/2030/labs/lab6/doc/eecs2030/lab6/package-summary.html

The programming question asks you to implement each method in the RecursiveMethods class recursively. Any use of loops is forbidden. You receive a zero if there is any occurrence of a loop (e.g., for, while).

0 0
Add a comment Improve this question Transcribed image text
Answer #1

public static String compressString(String str) <terminated> RecursiveMethods Java 16 17 18 19 20 21 if (str.length)) 899 ret

It is a big question, and everything can not be done in the given time limit.. However i have answered your first 4 part questions, i request you to please post other questions one in a thread, so that we can answer them better. Thanks!


import java.util.ArrayList;
import java.util.Arrays;

public class RecursiveMethods {

        public static String complementofDecimal​(int n) {
                if (n < 10) {
                        return ((char) ('0' + (9 - n))) + "";
                }
                int last = n % 10;
                String lastCom = ((char) ('0' + (9 - last))) + "";
                return complementofDecimal​(n / 10) + lastCom;
        }

        public static String compressString(String str) {
                if (str.length() == 0) {
                        return "";
                }
                int runLength = 1;
                while (runLength < str.length() && str.charAt(0) == str.charAt(runLength)) {
                        runLength++;
                }

                return str.substring(0, 1) + runLength + compressString(str.substring(runLength));
        }
        
        public static int yorknacci​(int n) {
                if(n <= 2) {
                        return 1;
                }
                if(n % 2 == 0) {
                        return yorknacci​(n-1) + yorknacci​(n-2);
                } else {
                        return yorknacci​(n-1) + yorknacci​(n-2) + yorknacci​(n-3);
                }
        }

        public static java.util.List<java.lang.Integer> YorknacciList​(int n) {
                if(n == 1) {
                        ArrayList<Integer> result = new ArrayList<>();
                        result.add(yorknacci​(n-1));
                        return result;
                }
                java.util.List<Integer> result = YorknacciList​(n-1);
                result.add(yorknacci​(n-1));
                return result;
        }
        
        public static void main(String args[]) {
                System.out.println(complementofDecimal​(100));
                System.out.println(compressString(""));
                System.out.println(compressString("bbbrrraaaaaazzzz"));
                
                System.out.println(Arrays.toString(YorknacciList​(5).toArray()));
        }
}
Add a comment
Know the answer?
Add Answer to:
Implement the class described by the following API. You do not have to include javadoc comments....
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Implement the AutoShop class described by this API. You do not have to include javadoc comments....

    Implement the AutoShop class described by this API. You do not have to include javadoc comments. The programming question asks you to implement a class that represents a auto shop that has an owner. The auto shop has a collection of vehicles, but the choice of which collection to use is left up to the student. In fact, students might choose to use more than one collection to implement the class. Students should analyze the API of the AutoShop class...

  • Using Java solve recursively without the use of loops or modifying the method signatures. /** *...

    Using Java solve recursively without the use of loops or modifying the method signatures. /** * Given a sorted input array a, return a sorted array of size a.length + 1, * consisting of all elements of array a and integer i. * * @param a an array that is sorted in a non-descending order * @param i an integer * @return a sorted array of size a.length + 1, consisting of all elements of * array a and integer...

  • Using loops with the String and Character classes. You can also use the StringBuilder class to...

    Using loops with the String and Character classes. You can also use the StringBuilder class to concatenate all the error messages. Floating point literals can be expressed as digits with one decimal point or using scientific notation. 1 The only valid characters are digits (0 through 9) At most one decimal point. At most one occurrence of the letter 'E' At most two positive or negative signs. examples of valid expressions: 3.14159 -2.54 2.453E3 I 66.3E-5 Write a class definition...

  • Design and implement a class for a one person guessing game as described on page 30,...

    Design and implement a class for a one person guessing game as described on page 30, Chapter 1, Programming Problem 7 of the textbook. CSCI 2421 HW1.jpg Submit header file guess.h, implementation file guess.cpp, main function file main.cpp that asks initial seed number, and prints three sequential numbers generated by the program. You need to include a makefile, and Readme file pseudocode version UF comments in your code. 6. Exercises 6, 7, and 8 ask you to specify methods for...

  • This assignment is designed to give you practice with Javadoc, creating unit tests and using Junit....

    This assignment is designed to give you practice with Javadoc, creating unit tests and using Junit. Be sure to follow all style and documentation requirements for THIS class. See the style and documentation requirements posted on Canvas. You are to name your package assign1 and your file Palindrome.java. Palindrome Class Palindrome testString : String + Palindrome (String) + isPalindrome (): boolean The method isPalindrome is to determine if a string is a palindrome. A palindrome, for this assignment, is defined...

  • Assignment4: Evaluate Arithmetic Expressions. Requirements: Implement a concrete ArrayStack class that extends the IStack interface as...

    Assignment4: Evaluate Arithmetic Expressions. Requirements: Implement a concrete ArrayStack class that extends the IStack interface as we discussed in the class (any other different Stack class implementation, even if it is implemented by yourself, will not receive any credit). Write a test class called Evaluate and a method that evaluates an arithmatic expression, which is given by a string. import java.util.Scanner; public class Evaluate { public static void main(String[] args) } // your implementation // obtain user's input from keyboard...

  • C PROGRAMMING Introduction In this part, you will solve a problem described in English. Although you...

    C PROGRAMMING Introduction In this part, you will solve a problem described in English. Although you may discuss ideas with your classmates, etc., everyone must write and submit their own version of the program. Do NOT use anyone else’s code, as this will result in a zero for you and the other person! Shipping Calculator Speedy Shipping Company will ship your package based on the weight and how far you are sending the package, which can be anywhere in the...

  • its about in C++ You will implement a simple calendar application The implementation should include a class named Calendar, an abstract class named Event and two concrete classes named Task an...

    its about in C++ You will implement a simple calendar application The implementation should include a class named Calendar, an abstract class named Event and two concrete classes named Task and Appointment which inherit from the Event class The Event Class This will be an abstract class. It will have four private integer members called year, month, day and hour which designate the time of the event It should also have an integer member called id which should be a...

  • Programming Assignment #2 (Arrays) I. The Assignment This assignment is to take your Garage class from...

    Programming Assignment #2 (Arrays) I. The Assignment This assignment is to take your Garage class from the previous assignment and modify it so that it uses an array of Car objects as the principal data structure instead of an ArrayList-of-Car. This is an example of the OOP principle of information hiding as your Car and test classes will not have to be modified at all. Unless you broke encapsulationon the previous assignment, that is   II. Specifications Specifications for all 3...

  • Objectives You will implement and test a class called MyString. Each MyString object keeps track ...

    Objectives You will implement and test a class called MyString. Each MyString object keeps track of a sequence of characters, similar to the standard C++ string class but with fewer operations. The objectives of this programming assignment are as follows. Ensure that you can write a class that uses dynamic memory to store a sequence whose length is unspecified. (Keep in mind that if you were actually writing a program that needs a string, you would use the C++ standard...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT