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 7941599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:43:07+00:00 2026-06-03T23:43:07+00:00

I am trying to create a few string sorting methods using an interface. The

  • 0

I am trying to create a few string sorting methods using an interface. The Application driver class calls the main SimplePriorityQueue object class, but it passes in a class implementing the interface as the argument when it makes this call. There are several classes implementing the interface (one to compare by length, one alphabetically (by value), one by reverse length, etc), which is why I’m told one constructor in the SimplePriorityQueue class should be able to handle them all.

When using the Eclipse debugger, the ‘source not found’ error pops up as soon as the Application class executes the line pq = new SimplePriorityQueue(new StringByLength()); as indicated in the code comment.

Here is what I have:


//the Interface
package cs15200.review.srijitag;

public interface Comparator {
    public int compare(Object o1, Object o2);

}

Here is one of the sorting classes. There are several more, but they are all almost exactly like this

//StringByLength class, which sorts by length
package example.cs151xx;

import java.util.Comparator;


public class StringByLength implements Comparator {

  public int compare(Object o1, Object o2)
  {
    String s1 = (String)o1;
    String s2 = (String)o2;
    return s2.length() - s1.length();
  }

  public boolean equals(Object o)
  {return (o instanceof StringByLength);}
}

//the relevant portion of the Application class

import example.cs151xx.Prompt;
import cs15200.review.srijitag.SimplePriorityQueue;

import example.cs151xx.StringByLength;
import cs15200.review.srijitag.StringByLengthReverse;
import cs15200.review.srijitag.StringByValue;
import cs15200.review.srijitag.StringByValueIgnoreCase;
import cs15200.review.srijitag.IntegerIncreasing;

import java.util.Comparator;


public class Application {

  ////////////////
  //Driver Program
  ////////////////

    public static void main(String[] args)
    {
    //Construct object to test; let the user specify what Comparator
    //  object to construct to order the priority queue

      SimplePriorityQueue pq;
      char howPrioritize = Prompt.forChar("Enter how to prioritize queue\n  v (by value)\n  i (value ignore case)\n  l (by length)\n  r (by reverse length)\n\nChoice","virl");
      if (howPrioritize == 'v')
        pq = new SimplePriorityQueue(new StringByValue());
      else if (howPrioritize == 'i')
        pq = new SimplePriorityQueue(new StringByValueIgnoreCase());
      else if (howPrioritize == 'l')
        pq = new SimplePriorityQueue(new StringByLength()); //ERROR THROWN
      else
        pq = new SimplePriorityQueue(new StringByLengthReverse());

[...more code to finish up rest of driver class]

//The relevant parts SimplePriorityQueue class which has the constructors, accessors, and methods

package cs15200.review.srijitag;

import example.cs151xx.StringByLength;
import java.util.Comparator;

public class SimplePriorityQueue{
    public SimplePriorityQueue(Comparator whatever){
        check = whatever;
    }

    public void enqueue(Object item){

        if(list.length==rear+1)
            doubleSize();
        if (rear==-1)
            list[0]=item;
        else{
            for(int i=rear;i>=0;i--){
                int z = check.compare(item,list[i]);
                if(z<=0){
                    list[i+1]=list[i];
                    list[i]=item;                       }
                else{
                    list[i+1]=item;
                }
            }
        }
        rear++;
    }

[...more accessors and mutators]

          //instance variables
    private Object[] list=new Object[1];
    private int rear=-1;
    private Comparator check;


}

I know this basic format (passing in as an argument the an object that implements the interface, and using as a parameter an object of the type of that interface) should work because I successfully tried the following simple example:

package  cs15200.review.srijitag;
import example.cs151xx.StringByLength;
import java.util.Comparator;

public class temp {


    public static void main(String[] args) {
        Comparator z = new StringByLength();
        System.out.println( z.compare("hi", "what's up"));
        Comparator y = new StringByValue();
        System.out.println(y.compare("hi", "what's up"));

        System.out.println( lookee(new StringByLength())); //should return the same result as z.compare(...)
        System.out.println(lookee(new StringByValue())); //should return the same result as y.compare(...)
    }

    public static int lookee(Comparator test){
        return test.compare("hi", "what's up");

    }
}

So what am I doing wrong in the constructor in the SimplePriorityQueue class? Thanks in advance for your help.

  • 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-06-03T23:43:08+00:00Added an answer on June 3, 2026 at 11:43 pm

    You implemented java.util.Comparator instead of cs15200.review.srijitag.Comparatorin which java.util.Comparator source not found when you debug.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the spirit of re-using code, I'm trying to create a few library projects.
I'm trying to create a Windows Form application that searches for a string and
Hell all, I am currently trying to create a few object dynamically in code.
I'm trying to create a check on a few columns in my database that
What i'm trying to create is a background worker that executes a few processes
I'm trying to create a script what permits me to select a few lines
I'm trying to learn JavaFX and maybe create a few learner games. I always
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
Ok so I am trying create a login script, here I am using PHP5
I've got a few questions about edittext.. I'm trying to create a login screen

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.