Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java tasks: Please help me with a single abstract class ( class Thing ) in this

ID: 3739173 • Letter: J

Question

Java tasks: Please help me with a single abstract class (class Thing) in this program.

This project is called Panic! We will describe a single-level floorplan of a building, filled with different kinds of people and different kinds of threats. We will simulate how the people seek to evacuate the building to safety, and how the threats spread throughout the building. Various events will be announced, such as person movements, threats spawning, and people reaching safety or succumbing to the threats. We will read a map representation from a file, and we will write the messages to either a file or just System.out as directed.

-----Here is the task-----

class Thing

Thing encompasses both persons and threats. This abstract class implements both Representable and Passable (though it relegates all methods from Passable to child classes).

Manual Inspection Criteria Reminder

For this class and its child classes, you need to use the provided (public) methods defined here when you can, rather than re-visiting the internal state. As an example, Thing::getLoc(), Thing::setLoc(), and Person::isSafe() should be used when they can rather than trying to re-invent the same computation.

Fields

private Coord loc, prevLoc

public final String repr

protected java.io.PrintStream log

protected Map map

Methods

public Thing(Coord c, String repr, Map map, PrintStream log). Initializes the fields. Both loc and prevLoc are set to the given coordinate c. (This is the only time they'll match).

public abstract void doAction(). All things can do an action. People might move, and threats might spawn or kill. This will be overridden lower in the class hierarchy.

public Coord getLoc(). Returns the loc.

public Coord getPrevLoc(). Returns the prevLoc.

public void setLoc(Coord c). Updates both prevLoc and loc appropriately.

@Override public String repr(). Returns the field.

@Override public String toString(). Returns the concatenation of repr() and getLoc(). For instance, an Avoider at location (2,3) would return "a@(2,3)".

-----Codes for interface classes----

Passable.java

public interface Passable {
  
public abstract boolean canLookThrough();
  
public abstract boolean canPassThrough();
}

-------

Representable.java

public interface Representable {

public abstract String repr();
}

Please help. I would greatly appreciate it. Thank you.

Explanation / Answer

import java.io.PrintStream;
import java.util.Map;

public abstract class Thing implements Representable, Passable{
private Coord loc, prevLoc;
public final String repr;
protected java.io.PrintStream log;
protected Map map;
  
public Thing(Coord c, String repr, Map map, PrintStream log){
loc = prevLoc = c;
this.repr = repr;
this.map = map;
this.log = log;
}
  
public abstract void doAction();
  
public Coord getLoc(){
return loc;
}
  
public Coord getPrevLoc(){
return prevLoc;
}
  
public void setLoc(Coord c){
prevLoc = loc;
loc = c;
}
  
@Override public String repr(){
return repr;
}
  
@Override public String toString(){
return repr+"@"+loc.toString();
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote