Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

I am trying to solve it , what am i supposed to do next?

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the question..



Consider the following generic interface definitions.
/∗∗
∗ Generic interface which defines an <code>apply</code> method which applies a task to its argument.
∗/
public interface Task<T> {
/∗∗
∗ Apply this instance's task to an object argument.
∗ @param object The object to which this task is applied.
∗/
public void apply( final T object );
}
/∗∗
∗ Generic interface for collections which allows for a traversal of the members of the collection
∗ and applying a task to each member of the collection.
∗/
public interface Traversable<T> extends Iterable<T> {
/∗∗
∗ Apply a task to each member of this <code>Iterable</code> collection.
∗ @param task The task which is applied to each individual member
∗ of this <code>Iterable</code> collection.
∗/
public void traverse( final Task<T> task );
}


Using the Task interface you may define a polymorphic Task object whose instance method apply( ) applies a task to an object reference argument.
E.g. consider the (polymorphic) Task objects print1 and print2.
Assume that the apply( ) method of the print1 object prints its argument once and that the apply( ) method of the print2 object prints its argument twice. Then print1.apply( object ) prints object once and print2.apply( object ) prints object twice.
The Traversable interface lets you define a polymorphic Traversable object which can traverse all members of an Iterable collection and apply a given task to each member of the collection.
Furthermore, assume we have a Traversable object traverser which visits all objects in a list. Then traverser.traverse( task1 ) prints each object in the list once and traverser.traverse( task2 ) prints each object in the list twice.
For this question you will implement a concrete class which implements the Traversable interface. The name of the class should be Traverser. The class should have a constructor which takes one parameter, which should be a Iterable object reference whose members are traversed by the instance method traverse( ) of the Traverser interface. You should be able to guess the signature of the constructors.



so Far i have created the class Traverser which is




The interface Trasversable




The interface Task





What am i supposed to do now according to the question i cannot figure out... please guys help me
 
Sheriff
Posts: 15525
263
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is confusing you? Break it down sentence by sentence and explain what you understand or don't understand about each one.
 
Junilu Lacar
Sheriff
Posts: 15525
263
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know one thing: I wouldn't make the Traverser class implement Task. That would just be confusing and I'm sure it's adding to yours.
 
Junilu Lacar
Sheriff
Posts: 15525
263
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This: "Then traverser.traverse( task1 ) prints each object in the list once and traverser.traverse( task2 ) prints each object in the list twice."

really should be this, given the context set up previously: "Then traverser.traverse(print1) prints each object in the list once and traverser.traverse(print2) prints each object in the list twice."
 
Junilu Lacar
Sheriff
Posts: 15525
263
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And this part just adds to the confusion: "For this question you will implement a concrete class which implements the Traversable interface. The name of the class should be Traverser."

By way of analogy, it's as confusing as these would be:

"... you will implement a concrete class which implements the Edible interface. The name of the class should be Eater."
"... you will implement a concrete class which implements the Drivable interface. The name of the class should be Driver."
"... you will implement a concrete class which implements the Readable interface. The name of the class should be Reader."
"... you will implement a concrete class which implements the Throwable interface. The name of the class should be Thrower."

You wouldn't call something that's edible an eater. You'd call it food.
You wouldn't call something that's drivable a driver. You'd call it a vehicle.
You wouldn't call something that's readable a reader. You'd call it a book (or e-book if you prefer).
You wouldn't call something that's throwable a thrower. You'd call it an Exception (or Error).

Therefore, it's silly and confusing to tell students to call something that's Traversable a "Traverser". Sheesh.
 
Poop goes in a willow feeder. Wipe with this tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic