Please help me with this using java. And comment the code The following is some code designed by J. Hacker for a video game. There is an Alien class to represent a monster and an AlienPack class that represents a band of aliens and how much damage they can inflict: 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; // Stores one of the three above types 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 Alien[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; // Snake does 10 damage } else if (aliens[i].type==Alien.OGRE_ALIEN) { damage +=6; // Ogre does 6 damage } else if (aliens[i].type== Alien.MARSHMALLOW_MAN_ALIEN) { damage +=1; // Marshmallow Man does 1 damage } } return damage; } } The code is not very object oriented and does not support information hiding in the Alien class. Rewrite the code so that inheritance is used to represent the different types of aliens instead of the “type” parameter. This should result in deletion of the “type” parameter. Also rewrite the Alien class to hide the instance variables and create a getDamage method for each derived class that returns the amount of damage the alien inflicts. Finally, rewrite the calculateDamage method to use getDamage and write a main method that tests the code

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Please help me with this using java. And comment the code The following is some code designed by J. Hacker for a video game. There is an Alien class to represent a monster and an AlienPack class that represents a band of aliens and how much damage they can inflict: 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; // Stores one of the three above types 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 Alien[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; // Snake does 10 damage } else if (aliens[i].type==Alien.OGRE_ALIEN) { damage +=6; // Ogre does 6 damage } else if (aliens[i].type== Alien.MARSHMALLOW_MAN_ALIEN) { damage +=1; // Marshmallow Man does 1 damage } } return damage; } } The code is not very object oriented and does not support information hiding in the Alien class. Rewrite the code so that inheritance is used to represent the different types of aliens instead of the “type” parameter. This should result in deletion of the “type” parameter. Also rewrite the Alien class to hide the instance variables and create a getDamage method for each derived class that returns the amount of damage the alien inflicts. Finally, rewrite the calculateDamage method to use getDamage and write a main method that tests the code.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 7 steps with 1 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education