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);
}

Recommended Answers

All 13 Replies

So any questions for us other than your assignments?

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?

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.

can you help me out with my code? it is due in 12 hours...

Sorry, this isn't a "we do your homework" service. I'll help you learn Java, but I won't do your homework.

I am reworking the program, can you please assist?

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

Yes. That is exactly what the spec asked for. I also find it confusing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.