Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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: ?

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

Documentation and Testing In terms of correctness, your class must provide all of the functionality described above and must satisfy all of the constraints mentioned in this writeup. In terms of style, we will be grading on your use of comments, good variable names, consistent indentation, minimal data fields and good coding style to implement these operations. You must use good documentation including Javadoc comments and tags as discussed in class. You welcome to research sources like https://www.geeksforgeeks.org/what-is-javadoc-tool-and-how-to-use-it/.You must include exactly what type of exception is thrown if a precondition is violated. Remember to mention all important behavior that a client would want to know about. Test your program by running your driver multiple times with different number of moves and giving or refusing shields to elves and wands to genies. Since a random number is used your output may not exactly match the

output given in this document. Run your program initially with number of moves =1, and gradually increase the number and the options for shield and wand. Test for number of moves =20. Take a screen shot of your output for number of moves =20, 10, 5, 1. Vary the shield and wand options.

Submission 1. all your class files (MagicalCreature.java, Elf.java, Dragon.java, Goblin.java and Genie.java) 2. your client programs (MagicalCreatureGame.java and MagicalCreatureHelper.java) 3. a document with the output of testing. Call this document Assignment2Test.doc.

Development Strategy One of the most important techniques for software professionals is to develop code in stages rather than trying to write it all at once (the technical term is iterative enhancement or stepwise refinement). It is also important to be able to test the correctness of your solution at each different stage. Use this execution chart for reference Execution Chart of the Driver. Main MagicalCreaturesHelper.fillData(c); // is the arraylist of creatures processLine(line); // this method reads a line from the data file, creates and returns a magical creature MagicalCreaturesHelper.playGame(c); // asks the user for number of moves and calls war method that many times war(c,in); // inputs the creature arraylist and scanner and randomly // selects a killer and victim. If the killer is a genie asks // wand option, if victim is elf asks shield option. Then // makes the killing move by invoking the kill method displayCreatures(c); // removes dead creatures from the arraylist and prints // the remaining creatures by using toString method

We are suggesting that you develop the program in multiple stages: Put all methods in helper file called MagicalCreaturesHelper.java. 1. In this stage we want to test constructing a MagicalCreature class and examining it's contents. So the methods we will implement are the constructor, the getters and setters and the toString method. Write a simple test program to create a magical creature and test its methods.

2. Now in your test program, practice creating an arraylist of magical creatures by hard coding in your program, declaration and construction of 3 or 4 magical creatures. Print the contents of this database and add and remove creatures from it. 3. Create one creature class, like Goblin. In your main program, practice creating goblins. You can use the data file given to you. Save a copy and make changes as needed to it for testing your program in a step wise manner. Change all types to Goblins in the data file and use it to create an arraylist of goblins. Implement the filldatabase method and the processLine method that it calls 4. Add another class like Dragon. Change your testing file as needed. Start working on the game and write the war method. 5. Add the rest of the classes and complete the rest of the implementation. 6. Test your program by using the original creatures.txt file given to you.

Expected Output When you run your program, test it for moves =1, 5,10, 20. Sample interactions are provided in the file Assigment2_SampleOutput.txt given to you. Your output may not exactly match the given one, due to use of random numbers but the final output (for moves =20) should be the same.

Use the data file creatures.txt

Toothy,Dragon,black,4 Glade,Elf,green,2 Gremlin,Goblin,yellow,44 Whoosh,Genie,purple,99 OldFire,Dragon,blue,345 Silverin,Elf,turquoise,19 Gaga,Goblin,white,512 Loompa,Genie,orange,99

question 1

image text in transcribedimage text in transcribedimage text in transcribed
Suppose we want to create an address book which contains na mesI phone numbers. emails, and other personal information. In the questions below, give support to your answers based on the typical operations {for example; finding a person by hisfher email} you might use. Explain whythe algorithm andfor data structure you use gives a good tradeoff between memory use and ru ntime complexity. Some of the questions below could require nested data structures [for example. a Map which has values that are Sets). a] Which data structures should you use for the address book in general to store the class Person? IGive reasoning for your answer. b] Suppose you have friends who live in various different cities. What data structure could be useful to nd these friends efficiently. You ca n suppose that each friend has a city eld associated with them. Give reasoning to your answer. Thinlc about search engines for this question. c} Suppose you want to checlc that there are no people with the same email address. Which algon'thm{s].idata structu reis} might you use to do this? Give reasoning for your answer. d] Suppose in you know which ofthe people in you address boolc are friends which each other. Now suppose you talce yourself out of the graph. Which algorithmlsJIdata structureis] would help you dete rrnine the num ber of unrelated groups of friends you have? Giye reasoning for your answer. e} Suppose you want to list your friends who have lvla rch birthdays in order of date. What algorith misjg'da'ta structure~[s] whould you use to accomplish this. You may assume that you have a birdiday field which has a Date class that contains date and month member variables. Declare any other assumptions you make and give reasoning for your answer. TOPIC: TF-IDF Compute the following from the data given below: Doc # Text (a) Term Frequency (TF) matrix for all documents 1 science test Docl Doc2 Doc3 2 Doc4 Doc5 math test 3 computer test test 4 not science test science not computer test math computer not (b) TF-IDF vector for the term computer Docl Doc2 Doc3 Doc4 Doc5 computerThis set of exercises requires the student to generate a computational model of the 10 motion of a spherical object dropped from a tall building. and then graph and analyze the output of the model. It also guides the student in exploring the accuracy of a computational algorithm by comparing the computational results with an exact solution obtained analytically. The numerical approach used is the simple Euler method. Exercises Exercise 1.: Computational Model of a Falling Sphere with Air resistance Produce a working co mputatio nal model of a sphere that has been dropped from rest from a very tall building using the simple Baler method. Assume that the sphere will move entirely in one dimension. and that it is subject to the constant gravitational force near Earth's surface and to a resistive force proportional to the square of the sphere's instantaneous speed. Exercise 2 Accuracy of Computational Model: 'v'elocity ys. Ti me Since the computational approach is based on an approximation. it is important to determine just how small Delta t should be for the approximation to accurately solve the 10 air resistance problem. Make a comparison between the time dependence ofthe velocity predicted by the computational modeL. and that predicted bythe exact result. v{t] = [sort[[2"m*g}f {Dm'tA * tanhsdrt{{D*g*A+g}.-'{2* mil +t}u} . Use parameters that describe a iii-pound bowling ball [you should look up the diameter. and convert to meters}. and let it fall a distance equivalentto the height of the Sears. oops - Willis. tower {440 m]. Assume the ball is initially at rest. Use a value of 0.5 for the drag coefcient. and the de nsityr of air near sea level. What value of Delta t do you deem to be sufficie ntly small forthe computational model to be accurate? Explain howI you arrived atthis value of Deltat . Exercise 3: Accuracy of Computational Model: Position vs. i'Ime Carry out the same comparison {computational vs. exact analytical solution} for the bowling ball's position as a function of time. The exact result forthe ball's position is given by yttjl = {-[ijlyr DgA} * |n[ coshI: sgrtt [Dqu]-I[2rn}}*t}] . Assume the bowling ball is falling the same distance of 440 m. Do you nd the same value of Delta t. astound forthe velocity comparison of Exercise 2. to be acceptable forthe position comparison

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions