Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java abstract problems: Please help me with two abstract classes ( class Threat ) and (class GreenSlime ) im this program called Panic. Here is

Java abstract problems:

Please help me with two abstract classes (class Threat) and (class GreenSlime) im this program called "Panic".

Here is the link to the introduction and some samples of this program: https://paste.ee/p/y2BqB.

Required classes for implemented and extended are provided at the bottom.

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

class Threat

public abstract class Threat extends Thing 

Threat is an abstract class that extends Thing. Threats are the bad things from which people are trying to escape. They spread (spawn) at regular intervals; we store how long it's been since the last spawning (via charge), and also at what point they will again spawn (via fullCharge).

Manual Inspection Criteria (2%) : Threat houses most of teh code related to increasing/resetting charge, and spawning potentially four children in four new locations. Child classes only define the specifics of spawning and any special additional actions during doAction().

Fields

protected int charge

protected final int fullCharge

Methods

public Threat(Coord c, String repr, int fullCharge, Map map, PrintStream log). Initializes the fields. charge starts at 0.

public abstract void spawn(Coord c). Child classes will provide an implementation that spawns (creates) a new thing identical to itself, but at the given clocation. During the spawn() method, a child places a copy of the new object on the map and carries out any further actions such eliminating unfortunate humans in their path. (do not call doAction here, only actions such as a GreenSlime immediately killing present people will occur).

@Override public void doAction(). First action is to increment charge. If it reaches fullCharge, it's time to spawn! When at full charge, take the following actions.Log a message of the form

g@(1,8) spreading 

which indicates the type and location of the threat that is spreading/spawning. (Hazes also can spread; ~@(1,8) spreading also appropriate).

Call the spawn(c) with a Coord for all four cardinal directions (north, east, south, west) from the spawning threat.

Only call spawn(c) if the spot canPassThrough() which is true for non-wall spots.

reset charge to zero.

Note: Threat doesn't provide implementations for any methods from Passable, so those are still the child classes' responsibilities.

-----

class GreenSlime

public class GreenSlime extends Threat 

It has no fields, but has a constructor and overrides various abstract methods it inherited, in order to be concrete.

Methods

public GreenSlime(Coord loc, Map map, PrintStream log). Via the parent constructor, sets all fields. fullcharge must always be 4, and the starting value for charge is 0.

@Override public void spawn(Coord c). Creates a new GreenSlime and adds it to the map at location c. The following considerations should be made

Do not spawn a new slime in a location that already has a green slime. This will require checking that there is no slime at the coordinate c.

Generate a log message of the form

g@(1,7) spawned 

where the location is the position of the new slime.

Any Person at the new spawn location is eliminated. When killing humans, call their die() method. Also generate a log message of the following form

g@(1,7) killed z@(1,7) 

@Override public void doAction(). After calling the version of doAction inherited from Threat, this GreenSlime object will check what non-dead persons are present at its location on the map, and kills them (calls their die() method). Since multiple people may be present, mulitple deaths may occur. Whenever a person is killed, a message must be sent to the log, utilizing toString() definitions. Example:

g@(4,5) killed a@(4,5) 

@Override public boolean canLookThrough(). People can actually look through a spot containing a GreenSlime; it doesn't obscure the whole view like a Walldoes.

@Override public boolean canPassThrough(). Return true here. A Person can attempt to pass through a green slime but it will result in death.

Suggestion: In several places, GreenSlimes must kill all humans at their location (during spawn() and doAction(). This suggests a private method to kill all humans at the slime's location is useful. Such a method might help with part of the manual inspection criteria.

--------Java codes for class Thing, class Representable and class Passible (used to extend)----------

Please open the link, because they are a little long. Thank you

class Thing: https://paste.ee/p/j6ULE

class Representable:

public interface Representable {

public abstract String repr();

}

class Passible:

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

}

Class Coord (Coord.java) : https://paste.ee/p/pgUlM

Here is the link to the overview of this program: https://paste.ee/p/LE1l0

Please read and help me, I would greatly appreciate your helps.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Next Generation Databases NoSQLand Big Data

Authors: Guy Harrison

1st Edition

1484213300, 978-1484213308

More Books

Students also viewed these Databases questions

Question

What is job rotation ?

Answered: 1 week ago