Write a Java interface named Searchable with two abstract methods: one named Way2Search that returns a String and another named MaxTime that returns an Integer. Be sure your code compiles and runs as expected. Name your Java file Searchable.java.

Although there is no compilitation errors, or any errors throughout the program. I do feel like this is not the right way. Please, any assistance will help out.

Searchable.java

package searchable;

public class Searchable {
    public static void main(String[] args) {

        Search s = new Search() {

            @Override
                public void Way2Search(String Topic) {
                System.out.print("How many times have the Packers won the Superbowl?");
        }

            @Override
                public void MaxTime(int Number) {
                System.out.print(" 4");
        }
    };
            s.Way2Search("How many times have the packers won the superbowl");
            s.MaxTime( 4);

}
}

Search.java

package searchable;

public abstract class Search {

    public Search(){
        System.out.print("Print: ");
}

    public abstract void Way2Search(String Topic);
    public abstract void MaxTime(int Number);
}

Write a Java interface named Searchable...

You have defined a class not an interface

... with two abstract methods: ...

your methods are not abstract

Be sure your code ... runs as expected

This makes no sense. You can't "run" an interface. Were there more specifications that you didn't innclude in you post?

Edited 4 Years Ago by JamesCherrill: edit

No, this was it. I do need assistance then, if I am not understanding this.

ok, I defined a class not an interface, and technically my methods are abstract if the first file was an interface?

A method is abstract if it has no body, eg
void m1(); // abstract
void m2() { // some code } // has a body, not abstract
Abstract methods must be declared withthe abstract keyword, unless they are in an interface (becuase all methods in an interface are abstract by definition).
YOur methods have bodies so are not abstract.

public abstract void Way2Search;
public abstract void MaxTime;
}

So it should look like this....

Method signatures must have a parameter list, even if it's empty. See my example above
And your spec specifies heh return types, and they're not void.

Edited 4 Years Ago by JamesCherrill: and...

Sure. Give it your best shot and post the results. If I'm not here to give you some feedback then I'm sure someone else will help.

I am assuming this is the answer that the professor wants.

//Interface Searchable
    public interface Searchable {
        public String Way2Search();
        public Integer MaxTime();
    }

all it states is write a java interface named Searchable with those two abstract methods. Nothing else. It is a bit confusing if you ask me

This article has been dead for over six months. Start a new discussion instead.