How to create these two interface in JAVA Interfaces collect any number of abstr
ID: 3736437 • Letter: H
Question
How to create these two interface in JAVA
Interfaces collect any number of abstract methods together as a new type. All methods in an interface are implicitly public. Any class that formally implements all these methods and promises the fact (with an implements clause) may be used as the type this interface creates. There are some more advanced ways to use interfaces that we won't need - creating default implementations, adding public static final fields, and extending other interfaces. Those are interesting concepts but we don't need them for this project.
1interface Representable
Representable things indicate how to be displayed on a Map. toString might have been used, but maps aren't the only time we might want to represent things as strings.
Methods
public abstract String repr();. Returns the (usually single-character-long) string representation. For instance, an exit may be represented by "e".
2interface Passable
We care if we are able to look past various things and spots on a map, and we also care if a human is able to walk past various things and spots on a map. The spots and things don't need to share a parent class, and only a couple methods are necessary to fulfill this behavior, so it's appropriate to use an interface.
Methods
public abstract boolean canLookThrough(). Can a human look through or beyond this entity? For open spaces, yes. For persons, yes we are able to look beyond them (they aren't transparent, but they also don't fully block the entirety of our vision in that direction; you can usually see down a hallway even if someone is currently in that hallway). For walls, no, and for haze, no - it's obscured the entire view. Each entity will describe its own properties.
public abstract boolean canPassThrough(). Regardless of visibility, can a human get through a spot on the map containing this entity? We can walk through open spots and haze, even though one we can look through and the other we cannot. Each entity will describe its own passability properties.
Interfaces collect any number of abstract methods together as a new type. All methods i an interface are implicitly public Any class that formally implements all these methods and promises the fact (with an iplements clause) may be used as the type this interface creates. There are some more advanced ways to use interfaces that we won' t need creating default implementations, adding public static tinal fields, and extending other interfaces. Those are interesting concepts but we don' t need them for this project. interface Representable Representable things indicate how to be displayed on a Nap. toString might have been used, but maps aren't the only time we might want to represent things as strings Methods public abstract String repr O. Returns the (usually single-character-long) string representation. For instance, an exit may be represented by "e". interface Passable We care if we are able to look past various things and spots on a map, and we also care if a human is able to wallk past various things and spots on a map. The spots and things don' t need to share a parent class, and only a couple methods are necessary to fulfill this behavior, so it's appropriate to use an nterface. Methods . public abstract boolean canLookThrough 0. Can a human look through or beyond this entity? For open spaces, yes. For persons, yes we are able to look beyond them (they aren't transparent, but they also don' t fully block the entirety of our vision in that direction you can usually see down a hallway even if someone is currently in that hallway. For walls, no, and for haze, no - it's obscured the entire view. Each entity will describe its own properties. public abstract boolean canPassThrough0. Regardless of visibility, can a human get through a spot on the map containing this entity? We can walk through open spots and haze, even though one we can look through and the other we cannot. Each entity will describe its own passability properties. Manual Inspection Criteria Reminder these two methods in the interface should be called when appropriate, rather than checking for individual types of objects. One hint you need to approach things differently would be excessive (any?) uses of instanceorExplanation / Answer
Given below is the code for the question.
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i
Please do rate the answer if it was helpful. Thank you
Representable.java
----------------
public interface Representable {
public String repr();
}
Passable.java
---------------
public interface Passable {
public boolean canLookThrough();
public boolean canPassThrough();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.