Alien class below needs to be rewritten from an inheritance class to an abstract
ID: 3641305 • Letter: A
Question
Alien class below needs to be rewritten from an inheritance class to an abstract class.class alien
{
public static final int SNAKE_ALIEN = 0;
public static final int OGRE_ALIEN = 1;
public static final int MARSHMALLOW_MAN_ALIEN = 2;
public int type;
public int health; // 0=dead, 100=full strength
public String name;
public Alien(int type, int health, String name)
{
this.type = type;
this.health = health;
this.name = name;
}
}
public class AlienPack
{
private Alien[] aliens;
public AlienPack(int numAliens)
{
aliens = new Aliens[numAliens];
}
public void addAlien(Alien newAlien, int index)
{
aliens[index] = newAlien;
}
public Alien[] getAliens()
{
return aliens;
}
public int calculateDamage()
{
int damage = 0;
for( int i=0; i<aliens.length; i++ )
{
if (aliens[i].type==Alien.SNAKE_ALIEN)
{
damage +=10;
}
else if( aliens[i].type==Alien.OGRE_ALIEN)
{
damage +=6;
}
else if( aliens[i].type==Alien.MARSHMALLOW_MAN_ALIEN)
{
damage +=1;
}
}
return damage;
}
}
The rewritten Alien class should be made abstract since there will never be a need to create an instance of it, only its derived classes. Change this to an abstract class and also make the getDamage method an abstract method. So basically the whole Alien class and getDamage need to be made abstract.