please write the project below in java

Get quality term paper help at Unemployedprofessor.net. Use our paper writing services to score better and meet your deadlines. It is simple and straightforward. Whatever paper you need—we will help you write it!


Order a Similar Paper Order a Different Paper

  • The objective of this project is to apply interfaces to design several classes which are similar in outward behavior but very different in nature. This project will involve implementing several different types of location (a location on a map, or in a room of a house, or abstractly inside a list).

    Overview:

    1. 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.
    2. Create an enumeration, Direction, which provides the four major compass directions.
    3. Create the class MovingEntity, which is an entity which can move around to different locations and prints messages describing its progress.
    4. Create the location class MapLocation, which tracks an x, y coordinate pair as the entity moves around a map.
    5. Create an EnterableArray class, which is a glorified ArrayList which can be treated as a location.
    6. Create a Room class, which represents a room in a house. A number of entities can move around the house at the same time.
    7. 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.

    1. You may import any standard Java library if you see the need.
    2. The main method will not be tested; you may use it any way you want.
    3. All fields must be declared private or protected. This will be verified manually.
    4. 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).
    5. 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 NamedAn 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 NamedA 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.

    Direction: (10p)
    public enum DirectionThis is an enumeration which represents the four compass directions, north, south, east, and west. The actual members of the enumeration will be N, S, E, and W (in that order), but they will each have an overridden toString() method which holds the string values "north", "south", "east", and "west".

    • private Direction(String name) initializes the element of the enumeration using the given name.
    • @Override public String toString() returns the name of the direction (i.e. "north").

    MovingEntity: (15p)
    public class MovingEntity implements EntityNow we actually implement our actor which moves around to different locations. This actor has a name and a location (the location may be null if it isn’t anywhere at the moment). The actor also has the capability to move from one place to another, see what its neighbors are. It is also a talkative actor, so whenever it moves to another place, it will announce the fact, by printing to system output.

    • public MovingEntity(String name) construct a new actor with the given name and a null location.
    • @Override public String getName() what is the actor’s name?
    • @Override public void setLocation(Location loc) set a new location for the actor; in addition to simply setting the new location, this should do two other things: first, if the actor is currently at a location, it must leave() that location (see the Location.leave(Entity) method, and beware of creating an infinite loop); second after it sets a new location, it should announce the fact by printing the following line: entity_name moves to location_name
    • @Override public Location getLocation() where is the actor right now?
    • public Location[] getNeighbors() what is the entity’s list of neighbors right now (see Location.getNeighbors())? If the current location is null, then return an empty list.
    • public void move(int i) move the actor to the ith location in the neighbor’s list.
    • public void move(Direction d) move the actor in the given direction (assuming that the direction corresponds to list index, i.e. N is 0, S is 1, etc). Additionally, the entity should report its movement by printing: entity_name goes direction

    MapLocation: (15p)
    public class MapLocation implements LocationThis is a location on a map, expressed as a 2D pair of integer coordinates, x and y. If you begin at position (0, 0) in the map, then moving north would take you to (0, 1), east would take you to (1, 0), etc. Each set of coordinates is its own location, and there can be any number of coordinates, so don’t rely on pre-allocating all possible coordinates.

    • private final int x the x-coordinate.
    • private final int y
    • public MapLocation(int x, int y)
    • public int getX()
    • public int getY()
    • @Override public String getName() this should produce the same output as toString() (see below).
    • @Override public void enter(Entity e) simply inform the entity (see entity.setLocation()) that it has entered this location.
    • @Override public boolean leave(Entity e) inform the entity that it has left the location (i.e. set the location to null) and return true; beware of infinite loops!
    • @Override public Location[] getNeighbors() create and return a list of this location’s neighbors. The neighbors are the locations one coordinate to the north, south, east, and west (in that order).
    • @Override public String toString() returns the coordinates of the location as an ordered pair; so for example, if x is 2 and y is 4, then this method will return "(2, 4)".

    EnterableArray: (15p)
    public class EnterableArray extends ArrayList<Entity> implements LocationHere we start to see why it makes sense for Location to be an interface. An EnterableArray is just an ArrayList of Entity elements, but a list is a place where an element can go, so it’s possible to treat it as a location. This class just extends the ArrayList class by adding the necessary methods which will make it behave like a Location. Since we’ve already chosen a base class, we wouldn’t be able to do this without using an interface.

    • public EnterableArray() doesn’t need to do anything special.
    • @Override public void enter(Entity e) add the Entity to the list, but be sure to notify the entity that it’s been added.
    • @Override public boolean leave(Entity e) remove the entity from the list, returning whether it was successful or not; don’t forget to notify the entity that it’s been removed (by setting its location to null
    • @Override public String getName() returns the string "EnterableArray".
    • @Override public Location[] getNeighbors() returns a list with zero elements.

    Room: (15p)
    public class Room implements LocationA Room is a room in a house or a building. It has a name, and it has a list of people who occupy it (hint: would inheriting from an EnterableArray be useful here?). Furthermore, it has a list of links to all of the other rooms which it is connected to (hint: another ArrayList?). Moving from one room to another would typically involve picking from the neightboring rooms. The entity which leaves a room is no longer part of the list of people in that room, and is now part of the list of people in the new room.

    • public Room(String name) construct a room with the given name.
    • @Override public void enter(Entity e) the reason for this override is because we should now also print who’s in the room every time a new entity enters. The message would look like (ArrayList‘s toString() is suitable for printing the list of entities): entity_name now contains list_of_entities
    • @Override public String getName() what is the name of this room?
    • @Override public Location[] getNeighbors() which rooms are neighbors of this room? Note that this should be returned as a list of Location, which is not the same as an ArrayList!
    • public static void link(Room r1, Room r2) create a link between the two rooms r1 and r2, so that each one becomes a neighbor of the other one.

    JavaDoc: (15p)
    All of your public methods, classes, interfaces, and enumerations must be documented using JavaDoc-style comments. This includes declaring method parameters and return types.

Writerbay.net

Our affordable academic writing services save you time, which is your most valuable asset. Share your time with your loved ones as our Unemployedprofessor.net experts deliver unique, and custom-written paper for you.

Get a 15% discount on your order using the following coupon code SAVE15


Order a Similar Paper Order a Different Paper