Results 1 to 9 of 9
Thread: Gunner class implementation
- 12-25-2012, 02:15 PM #1
Member
- Join Date
- Dec 2012
- Posts
- 6
- Rep Power
- 0
Gunner class implementation
Hey i'm having a hard time with this task(Code below):
I need to write class Gunner which extends abstract class GunnerA. The task of the class is to destroy the target using ShootingRules interface. Gunner class has to destroy the target using information "to close/ to far" and with the least number of shots possible.
Extra info: I can't modify GunnerA class, Gun and ShootingRules interface. Gunner class have to use no-argument constructor.
Can you give me any tips how to start ? some examples ?
Java Code:public abstract class GunnerA { public abstract void weaponry( ShootingRules sr ); public abstract void destroyTarget(); }Java Code:public interface Gun { public double getBulletMinStartingSpeed(); public double getBulletMaxStartingSpeed(); // minimum & maximun angle from which the barrel can/will shoot public double getBarrelMinAngle(); public double getBarrelMaxAngle(); public void setBulletStartingSpeed( double speed ); public void setBarrelAngle( double angle ); public void shoot(); }Java Code:public interface ShootingRules { public Gun getGun(); public int getShootingResult(); }Java Code:class Gunner extends GunnerA implements ShootingRules { @Override public Gun getGun() { return null; } @Override public int getShootingResults() { return 0; } @Override public void weaponry(ShootingRules sr) { } @Override public void destroyTarget() { } }
-
Re: Gunner class implementation
I can tell you that you need to use composition rather than inheritance. A Gunner logically *is-not* a ShootingRules and thus should not implement this interface. Instead, a Gunner should *contain* a ShootingRules object.
- 12-25-2012, 03:37 PM #3
Member
- Join Date
- Dec 2012
- Posts
- 12
- Rep Power
- 0
-
Re: Gunner class implementation
Sure. When deciding whether one class should descend from another, the first class must satisfy the is-a rule. So for instance a Dog may descend from a Carnivore class or interface or an Animal class or interface or Pet class or Interface, but there should be no inheritance relationship between Dog and Kennel. Instead we would use the composition rule for this since a Kennel has-a Dog (or likely multiple Dogs).
Now if I am understanding the original poster correctly, a Gunner is someone who uses a Gun or some other Weapon while ShootingRules would be logical rules that dictate perhaps how the weapon should be used. In no way shape or form does Gunner satisfy the "is-a" rule for ShootingRules. Rather Gunner will likely have a ShootingRules object that it checks before it uses the weapon.
- 12-25-2012, 05:15 PM #5
Member
- Join Date
- Dec 2012
- Posts
- 6
- Rep Power
- 0
Re: Gunner class implementation
Ok, so if i'm correct my Gunner class "template" should look sth like this?:
Java Code:class Gunner extends GunnerA { ShootingRules sr = new ShootingRules() { public int getShootingResults() { return 0; } public Gun getGun() { return null; } }; public void weaponry(ShootingRules sr) { } public void destroyTarget() { } }
- 12-25-2012, 05:16 PM #6
Member
- Join Date
- Dec 2012
- Posts
- 12
- Rep Power
- 0
Re: Gunner class implementation
-
Re: Gunner class implementation
-
Re: Gunner class implementation
- 12-25-2012, 08:23 PM #9
Member
- Join Date
- Dec 2012
- Posts
- 12
- Rep Power
- 0
Similar Threads
-
Cross-Class Implementation
By FreakyCheeseMan in forum New To JavaReplies: 1Last Post: 08-14-2012, 09:33 AM -
Abstract class, implementation, getName()?
By manalinik in forum New To JavaReplies: 2Last Post: 12-27-2011, 02:08 PM -
Class within one class implementation
By gomdohri in forum New To JavaReplies: 1Last Post: 10-18-2011, 02:05 AM -
Implementation Class for RMI App, Compile-Time Error
By Jacob1028555 in forum NetworkingReplies: 22Last Post: 06-09-2011, 05:14 PM -
Help with implementation of the DataSet class
By silvia in forum New To JavaReplies: 1Last Post: 08-07-2007, 05:47 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks