Question
Please Code in Java: Overview: Create the three primary interfaces used in this project, Named, Entity and Location. an entity can be moved around to
Please Code in Java:
Overview:
Create the three primary interfaces used in this project, Named, Entity and Location. an entity can be moved around to different locations, while locations can be moved to and away from.
Create an enumeration, Direction, which provides the four major compass directions.
Create the class MovingEntity, which is an entity which can move around to different locations and prints messages describing its progress.
Create the location class MapLocation, which tracks an x, y coordinate pair as the entity moves around a map.
Create an EnterableArray class, which is a glorified ArrayList which can be treated as a location.
Create a Room class, which represents a room in a house. A number of entities can move around the house at the same time.
Document all public methods, classes, interfaces and enumerations using JavaDoc style comments.
We often run into situations where we can think of a lot of different things which behave in a very similar way at some level, but which are in fact very different in nature. Consider a location - something which you can go to or leave. The idea is a simple one, but it can apply to many different types of things. From where you are inside your home, to coordinates on a GPS map, to a spot on a game board. For these situations, it may make sense to use interfaces. Interfaces allow us to preserve some level of compatibility between different objects, without constraining them to be too similar. We may even want to derive from different existing classes, which would preclude us from using most other approaches besides interfaces.
In this project, we create two related interfaces, representing entities and locations, and use them to produce several different types of location-based classes.
Instructions:
You may import any standard Java library if you see the need.
The main method will not be tested; you may use it any way you want.
All fields must be declared private or protected. This will be verified manually.
You may write your own helper methods, but any methods which are specifically asked for must match exactly (i.e. capitalization of the method name; number and order of the parameters).
Any class, interface, and enumeration, as well as any public method, must be documented using JavaDoc style of comments.
Named: ( 5p) public interface Named
The Named interface consists of objects which have been given a name. It is comprised of one single method,
public String getName() lots of different things can have a name. This interface could represent any of them.
Entity: (5p) public interface Entity extends Named
An Entity is something which can move around from place to place. It has a name which it has inherited from Named. In normal usage, setting a location would first involve calling setLocation with null (in order to leave the previous location), and then immediately set location again with the new location.
public void setLocation(Location loc) typically this method would cause the entity to leave a previous location (if one was defined) and update the current location..
public Location getLocation() report back the current location of the entity.
Notice how Entity has a couple of methods which have Location as a parameter or return type? It's ok for two interfaces to depend on one another.
Location: (5p) public interface Location extends Named
A location has a name, but it can also be entered or left by an Entity. Furthermore, it can have a set of neighbors, which can be returned as a list.
public void enter(Entity e) enter the Location; this may involve informing the Entity that it's been added, and possibly recording the presence of the entity.
public boolean leave(Entity e) the opposite of enter, this may involve informing the entity that it's left, and possibily removing the entity from some list; also returns true if the removal was successful.
public Location[] getNeighbors() returns a list of Locations which represent neighbors of the current location.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started