Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6824151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:52:04+00:00 2026-05-26T21:52:04+00:00

There’s a LinkedQueueClass that has 3 elements: ABC XYZ 123 The elements inside the

  • 0

There’s a LinkedQueueClass that has 3 elements:

"ABC" 
"XYZ" 
"123"

The elements inside the LinkedListQueue are of custom class type StringElement which has one data member, it holds a string (word data member).

StringElement:
http://pastebin.com/zh0t2X5K

When I try to use the search() function to search for an element that actually exists in the queue the boolean value it returns is false. Means that it can’t find the element.

Main:
http://pastebin.com/vGegkcLZ

Where I went wrong?

EDIT (Code from Pastebin.org links mentioned above.)

Main:

public class StringElement extends DataElement {

    protected String word;

    public StringElement(String str)
    {
        word = str;
    }

    public StringElement(StringElement otherElement)
    {
        word = otherElement.word;
    }

    @Override
    public boolean equals(DataElement otherElement) {
        StringElement temp = (StringElement) otherElement;
        return (word == temp.word);
    }

    @Override
    public int compareTo(DataElement otherElement) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void makeCopy(DataElement otherElement) {
        StringElement temp = (StringElement) otherElement;
        word = temp.word;
    }

    @Override
    public DataElement getCopy() {
        StringElement temp = new StringElement(word);
        return temp;
    }

    @Override
    public String toString()
    {
        return String.valueOf(word);
    }

}

StringElement:

import java.util.Scanner;

public class Run {
    public static void main(String args[]){
        LinkedQueueClass strQueue = new LinkedQueueClass();    

        strQueue.addQueue(new StringElement("ABC"));
        strQueue.addQueue(new StringElement("XYZ"));
        strQueue.addQueue(new StringElement("123"));

        System.out.println();

        //ask user for a keyword to search for
        System.out.print("Search keyword: ");
        Scanner scan = new Scanner(System.in);
        String userInput;
        userInput = scan.next();

        //place the entered keyword into a StringElement and use it
        //to search for the element with mathing keyword
        StringElement keyword = new StringElement(userInput);
        System.out.println(keyword.toString());//debugging: to confirm userInput value got stored in keyword object
        System.out.println(strQueue.search(keyword));//search returns false


    }
}

search() from UnorderedLinkedList:

public boolean search(DataElement searchItem)
    {
        Node current; //pointer to traverse the list
            boolean found;

            current = first;  //set current pointing to the first
                                                  //node in the list

                found = false;    //set found to false

                while(current != null && !found)                //search the list
                        if(current.info.equals(searchItem)) //item is found
                        found = true;
                        else
                                current = current.link; //make current point to
                                                                        //the next node
                return found;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:52:05+00:00Added an answer on May 26, 2026 at 9:52 pm

    Solution

    Overriding DataElement’s abstract equals() method like so:

    public boolean equals(DataElement otherElement) {
            StringElement temp = (StringElement) otherElement;
            return (str.compareToIgnoreCase(temp.str) == 0);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is a website called Gild.com that has different coding puzzles/challenges for users to
There is a class that's a fully fledged UIViewController and when that page loads
There is a conversion process that is needed when migrating Visual Studio 2005 web
There are a few ways to get class-like behavior in javascript, the most common
There are several types of objects in a system, and each has it's own
There is a field in my company's Contacts table. In that table, there is
That's pretty much it. I'm using Nokogiri to scrape a web page what has
There are a TextField , a ListBox and a TextArea inside my Form .
I've got a string that has curly quotes in it. I'd like to replace
There is no doubt that MonoTouch is one of the great cross-compiler(s). Similarly, SenchaTouch

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.