Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question: In this programming assignment you will practice using ArrayLists, Inheritance and Polymorphism. You are to write a game called Magical Creatures War. You will

Question: In this programming assignment you will practice using ArrayLists, Inheritance and Polymorphism. You are to write a game called Magical Creatures War. You will do this by implementing a class called MagicalCreature that can be used to create a magical creature that is defined by a name, type, color and age. All of these characteristics are of String type except age which is an integer. There is one attribute that keeps track of whether the creature is alive or dead. Use a Boolean variable called alive to store this information. There are four types of magical creatures: Dragon, Elf, Genie and Goblin. Write four derived classes for each of these creatures using the tables given below: Write a main program for the game using the rules given.

Your MagicalCreature class should have the following public methods. It should be saved in a file called MagicalCreatures.java

Method Description MagicalCreature(String name, String type, String color, int age) : Constructor that sets the attribute values as received in the parameters

String getName(), String getType(), String getColor(), int getAge(), boolean getAlive() : Getters, one for each of the attributes

void setName(String name), void setType(String type), void setColor(String color), void setAge(int age), void setAlive(boolean alive) : Setters, one for each of the attributes , if alive is true, then the creature is alive otherwise it is dead. You can cause a live creature to die by setting alive to false.

void kill() : Prints the string "I do not have the license to kill ");

void die() : Sets the attribute alive to false. This causes the creature to "die"

String toString() : Returns a string "My name is " + name +" I am a "+color+" " +type+" I am "+age +" years old ";

Create the classes for the four derived types using the tables given below. Note that all attributes will have private access and all instance methods will be public.

Keep the following game rules in mind: Rules of the game: ? Dragons cannot be killed. ? A young dragon who is under 40 years old cannot kill ? Elves and Goblins cannot kill ? Elves can have a shield. Those with a shield cannot be killed ? Genies can have wands. Only Genies that have a wand can kill ? Creatures cannot kill themselves

Class Dragon This class has no attributes. It is a sub class of MagicalCreatures. Save in Dragon.java Method : Description Dragon(String name, String type, String color, int age) : Constructor. Calls the constructor of the parent class. String toString() : Returns the MagicalCreatures toString information plus " I breathe fire ". void kill(MagicalCreature other) : Overrides the MagicalCreature method. If it's a younger dragon, prints "I am too young to kill !". Otherwise kills the other dragon by causing it to die void die() : Overrides the MagicalCreature method. Prints "I am a dragon - nobody gets to kill me !"

Class Elf Method : Description This class is a sub class of MagicalCreature and has an attribute of boolean type called shield. Save class in file Elf.java Elf(String name, String type, String color, int age) : Constructor. Calls the parent class' constructor. Initializes shield to false

String toString() : Returns the MagicalCreatures toString information plus " I eat leaves, I have "+ a +"shield"; or " I eat leaves, I have "+ no +"shield"; depending on whether it has a shield or not. void setShield(boolean shield) : Sets the shield attribute accordingly

Class Goblin Method : Description This class is a sub class of MagicalCreature. Save class in file Goblin.java Goblin(String name, String type, String color, int age) : Constructor. Calls the parent class' constructor. String toString() : Returns the MagicalCreatures toString information plus " I kill elves if they do not have shields ";.

Class Genie Method : Description This class has an attribute of boolean type called wand. Save class in file Genie.java Genie(String name, String type, String color, int age) : Constructor. Calls the parent class' constructor. Initializes wand to false String toString() : Returns the MagicalCreatures toString information plus " I eat leaves, I have "+ a +"wand"; or " I eat leaves, I have "+ no +"wand"; depending on whether it has a wandor not. void setWand(boolean wand), boolean getWand() : Sets the wand attribute accordingly

void kill(MagicalCreature other) : If it has a wand, it causes the other creature to die (if the other is not a Genie). If it does not have a wand, it prints "I cannot kill without my wand !"

In addition to the above, write a client or driver program called MagicalCreaturesGame.java that allows the user to play a war game as follows: ? Read the creatures information from a text file called creatures.txt. Each creature occupies one line in the data file and contains name, type, color and age. ? Create and populate an ArrayList of MagicalCreatures by processing one line at a time of the data file. The line of text is to be split using the split method into an array of String containing four String tokens representing the four attributes. ? The war game consists of moves. The number of moves is decided by the user. Each move consists of an attack by one magical creature on another. The attacker and victim both need to adhere to the rules of the game which will decide if the attacker is eligible to kill or the victim is a candidate that can die. In each move, the selection of the attacker and victim is done randomly using the Random class. ? After each move, dead creatures are removed from the game, (from the Arraylist) and the list of creatures that are still alive is printed.

Review of Inheritance and Polymorphism and other java classes Make sure to review the Random Class, Character class, Integer class (parseInt method for converting String to integer) ArrayList methods. Read the chapter on Inheritance and Polymorphism to understand how overriding works. Make note of declaring objects of super class type and actually constructing or creating them of the sub class type. You will also need to use the instanceof method to determine the class of an object while dealing with functions that use polymorphism. Casting of objects is another feature that may be necessary

question 1

image text in transcribedimage text in transcribedimage text in transcribed
In 2013 SDSU had degree completion rates for Computer science that was 68%, 18% are Applied mathematics. 82.5% have a Computer science or Applied mathematics degree Find the probability that a student did not get a computer science degree nor Applied mathematics, b. Find the probability that a student has a Computer Science and Applied mathematics degree. C. Find the probability that a student has either a Computer Science degree or Applied mathematics degree but not both. Use a Venn diagram to display this event and then compute the probability.8.2-19. Consider the transportation problem having the following parameter table: Destination 2 Supply 5 Source N - 4 Demand W (a) Using your choice of a criterion from Sec. 8.2 for obtaining the initial BF solution, solve this problem manually by the transportation simplex method. (Keep track of your time.) (b) Reformulate this problem as a general linear programming problem, and then solve it manually by the simplex method. Keep track of how long this takes you, and contrast it with the computation time for part (a).Problem: Study the steady flow around a circular cylinder (see 'Problem Specification' in the Tutorial), by using the following two methods: 1. Theoretical: Potential flow (Section 6.6.3) 2. Computational: ANSYS finite element model (note: specific interface/steps may be slightly different from the provided tutorial) Requirements: Report should include Introduction, Theory, Computational Model, Results, and Conclusions, Discussion, and References. Use 1" margin on top, bottom, left, and right. Use Times New Roman 12 font and 1.5 line spacing. In Results session, present and compare the velocity field, streamlines, and drag forces on the cylinder from both the theoretical and computational results. In Discussion, discuss why these results from two approaches are similar or different

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

Step: 3

blur-text-image

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

Unity From Zero To Proficiency Beginner A Step By Step Guide To Coding Your First Game

Authors: Patrick Felicia

1st Edition

1091872023, 978-1091872028

More Books

Students also viewed these Programming questions