Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am trying to call an overloaded method in my client but it continues to produc

ID: 3854823 • Letter: I

Question

I am trying to call an overloaded method in my client but it continues to produce an error.

methods:

    public boolean contains(E e) { // begin boolean contains method
        Node temp = head;
        for (int i = 0; i < size; i++) {
            if (e.equals(temp.element)) {
                return true;
            }
            temp = temp.next;
        }
        return false;
    } // end boolean contains method
  
        public int[] contains(E e, int[] b) { // begin boolean overloaded contains method
        Node temp = head;
        int count = 0;
        for (int i = 0; i < size; i++) {
            count = i;
            if (e.equals(temp.element)) {
                b[0] += count;
                return b;
            }
            temp = temp.next;
        }
        b[0] += count;
        return b;
    } // end boolean contains method

Here is the implementation with the errors pointed out:

public static void main(String[] args) {
    int[] array = new int[0];
    MyLinkedList[] list = new MyLinkedList[26];
  
        for(int i = 0 ; i< list.length; i++) {
               list[i] = new MyLinkedList<>();
        }
           int count = 0;
         
        try {
            // Open the file that is the first
            // command line parameter
            FileInputStream fstream = new FileInputStream("random_dictionary.txt");
            // Get the object of DataInputStream
            DataInputStream in = new DataInputStream(fstream);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            String strLine;
            while ((strLine = br.readLine()) != null) {             
                for (int i = 97; i < 123; i++) {
                    if (strLine.charAt(0) == i) {
                        list[count].add(strLine.toLowerCase());
                        }
                    count ++;
                    }
                }
            }
        catch (Exception e){//Catch exception if any
            System.err.println("Error: " + e.getMessage());
            } // end catch

        try {
            // Open the file that is the first
            // command line parameter
            FileInputStream fstream = new FileInputStream("oliver.txt");
            // Get the object of DataInputStream
            DataInputStream in = new DataInputStream(fstream);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            String strLine;
            while ((strLine = br.readLine()) != null) {
                 for (int i = 97; i < 123; i++) {
                    if (strLine.charAt(0) == i) {
                        if (list[i - 97].contains(strLine) == true) {
                            wordsFound ++;
                            compsFound += list[i - 97].contains(strLine, array); //ERROR
                        }
                        else {
                            wordsNotFound ++;
                            compsNotFound += list[i - 97].contains(strLine, array); //ERROR
                        }
                    }
                }
            }
        }
      
        catch (Exception e){//Catch exception if any
            System.err.println("Error: " + e.getMessage());
            } // end catch

Any help would be appreciated, Thanks!

Explanation / Answer

The error is: return type of contains(E e, int[] b) is int[] and in the main function you are performing
                         compsFound += list[i - 97].contains(strLine, array); //ERROR

In java you cannot add integer arrays :(

I dont know your need, so cannot help you mare than this

If the error is still there, please let me know. Since I dont have the complete code, debugging the code and having the exacerror is not possible.

Let me know in the comment section what do you observe.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote