Starting from:

$29

HW4 2 Critter Simulator

Objectives: 6 We have several objectives for this project. 7 • You will work with an inheritance hierarchy that has an abstract base class. The 8 abstract base class will have public, private and protected components, concrete 9 methods and abstract methods, and both static and non-static elements – a little bit 10 of everything. You’ll make concrete subclasses of this class and write “object11 oriented” code that operates on instances of the subclasses in a polymorphic fash12 ion. 13 • We’ll introduce you to the concept of the Model-View-Controller (MVC) soft14 ware architecture. Our model will be a simple simulation. The controller in part 1 15 will be a text-based controller with very rudimentary commands entered from the 16 keyboard (technically, commands will be read from System.in, which of course 17 may not be a keyboard). The views for part 1 will similarly be very rudimentary 18 and will consist of a text representation of the simulated world sent to System.out. 19 During part 1, most of your effort will go into the model itself (i.e., writing the 20 simulator). In part 2, you’ll build a more interesting and useful view and control21 ler component. 22 23 2. Summary: 24 Imagine a 2-D rectangular grid of fixed length and width. Each grid point can be de25 scribed with a pair of co-ordinates (x, y). Imagine now that some of these grid points are 26 populated by Critters (i.e. animals or Algae plants). As time progresses in steps, the Crit27 ters can (i) move around the world (ii) fight other Critters when they find themselves on 28 the same grid location (iii) eat Algae (iv) reproduce and (v) die when they run out of en29 ergy. You will write a simulation model for this world in Java, where we specify the 30 rules for the above five activities. 31 32 Here is how the simulation model runs: 33 (i) The program is started up through a main() by the user. 34 (ii) The user is provided a prompt where he/she enters text commands. The first com35 mand might be to add a specified number of Critters of a specific type to the world mod36 el. 37 (iii) The user can now (or at any time) use the show command to print a view of the 38 world to the console. 39 (iv) The user can issue the step command to step through time a fixed number of times. 40 The world autonomously evolves as time passes, because of the activities listed in line 41 27. 42 (v) The user can use the quit command to finish the simulation. 43 44 45 6/24/18 8:32 PM 2 46 3. Instructions: 47 You may work in teams of two for this project. Each team should make only one submis48 sion to Canvas. All of the project source files MUST have the names and UTEIDs of both 49 students in the header at the top of the file. There will be no exceptions to this policy on 50 team projects. Collaborating on the project and failing to follow these instructions and 51 will be treated as a violation of academic honesty. 52 53 You may form your own team by finding a partner, or you may work on your own. 54 Please see the Canvas assignment page for instructions on how to form your team, and 55 the deadline for doing so. 56 57 You must write a simulator that supports the functionality for Critter described be58 low. Your simulator will be controlled with a text-based interface that accepts a few sim59 ple commands and produces a rudimentary representation of the world. All of your clas60 ses must be included in a java package called “assignment4”. You must create a class 61 Main inside this package, and the main() function for your simulator (i.e., the control62 ler) must be inside the Main class. 63 64 You must complete the Critter abstract class. There are several functions required in 65 Critter – some are static, some are protected and some are private. Please review both 66 the Critter.java file and the description below. You must implement all of the 67 methods defined in this class. You may not delete or change any of the fields or methods 68 already defined for Critter. You may add additional methods or fields to Critter 69 only if you make those new methods or fields private. 70 71 Note that the Critter class has one inner class called TestCritter. The Test72 Critter class is used to (1) implement the Algae critter, which is the primary source 73 of food within our simulated world, and (2) to test your projects during grading. You 74 must ensure that the setter functions in the TestCritter class work correctly with 75 your implementation of the Critter class and the simulation that you build. You must also 76 implement the other methods in TestCritter correctly for the grading to work. We 77 might discover more methods that we need for grading, and we will tell you that later. 78 You are free to add any other methods that you like in TestCritter to help your test79 ing. We will not be calling those methods in our grading, of course, but they should not 80 result in compile errors when we run your code. 81 82 As you implement the functionality for your Critter model, you may find that you 83 want to create additional classes. All of your classes must be in the assignment4 84 package. You must implement all of the functionality described below. However, we rec85 ommend that you build this project in stages. Suggestions are provided within the de86 scriptions below of the form [STAGE 1], [STAGE 2] or [STAGE 3]. You may, of 87 course, implement the functionality in any order that you wish; however, please keep in 88 mind that our grading process will assume that you worked on the stages in order (i.e., 89 that you completed all the STAGE1 functionality before implementing STAGE2). 90 6/24/18 8:32 PM 3 91 In addition to implementing the model, view, and controller for basic Critters such as 92 Craig and Algae (two critters that are included in your project kit), you must imple93 ment at least two distinct additional Critter classes per team member (i.e. four for a 94 team of two). Each Critter class must behave differently when modeled. Each Crit95 ter class must be in its own .java file. At the top of the java file, you must include a par96 agraph description in the comments that explains how this Critter class behaves in the 97 world. The description should be sufficient for the teaching assistant to easily determine 98 how each Critter class you create is different from every other Critter class. 99 100 4. Model components: 101 The model consists primarily of the Critter class, and subclasses of Critter. A 102 Critter is a simulated life form that lives in a 2-dimensional world. Critters have 103 (x,y) coordinates in an integer grid to describe their position in the world, and an ener104 gy value that represents the critter’s relative health. These values are represented with 105 private fields in the Critter class. When a Critter’s energy drops to zero (or be106 low) the critter dies and is removed from the simulation. You are provided with a Crit107 ter.java file that describes the minimum required functionality for your Critter. 108 Please refer to the file for details regarding our expectations for your solution. You are 109 also provided with a Craig.java file that implements a subclass of Critter. You 110 should not modify this file. Your implementation of Critter should work with the 111 Craig.java file provided to you. 112 113 5. Constant List: 114 There are a number of constants defined in the Params class. These constants are 115 static and final variables that identify parameters for the simulation. You must use 116 these parameter variables when implementing the simulation. The parameter values that 117 your program is tested with may be different than the values provided to you. The param118 eters in this file include: 119 • world_width – horizontal size of the world (integer units), typical values are 100-1000. We promise not to use values larger than 105 120 in our testing. Will never 121 be smaller than 10. 122 • world_height – vertical size of the world. Same range expectations and re123 strictions as world_width. 124 125 The coordinates in our world run from 0 (left edge) to world_width – 1 (right 126 edge) in the x dimension and from 0 (top edge) to world_height – 1 (bottom 127 edge) in the y dimension. This coordinate system was chosen to match the way most 128 graphics libraries work. 129 130 The simulated world is a 2-dimensional projection of a torus. That means that the 131 right-hand edge of the world is considered to be adjacent to the left-hand edge. Or, if 132 you prefer, that the world “wraps around” in both the horizontal and vertical dimen133 sions. When Critters move, if a Critter moves off the top of the world, you 134 should relocate that Critter to the bottom, and similarly for the four edges of the 135 world. 6/24/18 8:32 PM 4 136 137 The model understands eight directions – up, down, left, right and the four diagonals. 138 These directions are numbered such that the values roughly approximate the radians 139 around a circle – i.e., as direction increases in value, we move counter-clockwise in 140 angle. The 0 direction is straight right (increasing x, no change in y). The 1 direction 141 is diagonally up and to the right (y will decrease in value, x will increase). The 2 di142 rection is straight up (decreasing y, no change in x), and so forth. We will not test 143 your program with negative directions or with directions larger than 7. 144 145 • start_energy – the amount of energy assigned to a Critter when the crit146 ter is created at the start of the simulation. Note that this value is not the same as 147 the amount of energy a Critter will have when it is “born” as the offspring of an148 other Critter. See below for details about reproducing Critters during a simu149 lation run. 150 • walk_energy_cost – the amount of energy required to move one grid posi151 tion in any one of the eight directions in one time step 152 • run_energy_cost – the amount of energy required to move two grid posi153 tions in any one of the eight directions in one time step 154 • rest_energy_cost – the amount of energy required per time step in addition 155 to any other energy expended by the Critter in that time step, i.e., the energy spent 156 just standing still. 157 • min_reproduce_energy – the minimum amount of energy that a Critter 158 must have if it will reproduce. See reproduce below. 159 • photosynthesis_energy_amount and refresh_algae_count are 160 specific to the Algae class. See the discussion of Algae below. 161 You may alter this Params class file during your testing, as we will eventually replace it 162 with our own. 163 164 6. Critter collection: [STAGE1] 165 You must create and maintain a collection (e.g., List, or Set) of Critters. In this 166 collection you should store a reference to all the Critter instances that are currently 167 alive and being simulated. You can store your critter collection as a static data com168 ponent of the Critter class, or you can create a separate CritterWorld class that 169 stores the critter collection (and perhaps will store other information about the state of the 170 critter environment). Note that it does not make sense within the MVC architecture for 171 the critter collection (which is part of the model) to be stored within the Main class 172 (which is the controller). 173 174 The controller will populate this collection by invoking the static Crit175 ter.makeCritter() function. 176 • public static void makeCritter(String critter_class) – 177 create and initialize a Critter and install the critter into the collection and prepare 178 the critter for simulation. The critter’s initial position must be uniformly random 179 within the world, and the initial energy must be set to the value of the 180 Params.start_energy constant. 6/24/18 8:32 PM 5 181 If the random location selected for the critter is already occupied, the critter 182 should be placed into that position anyway. The encounter between the two crit183 ters now located in the same position will be resolved in the next time step (pro184 vided both critters are still in the same position at the end of that time step, see be185 low). 186 The type of critter is given by the argument critter_class. If crit187 ter_class does not exist or if critter_class is not a concrete subclass of 188 Critter, then this function must throw an “InvalidCritterException”. 189 To implement this function you will need to use the Class.forName() static 190 method and the newInstance non-static method for the class Class. 191 192 7. Time Steps: [STAGE1 except as noted below] 193 Our simulation consists of a sequence of time steps. During each time step, the state of all 194 Critters in the simulation is updated, new critters may be added, and critters may be 195 removed (births and deaths). All of the core functionality of the simulator is associated 196 with time steps. The Critter class has two methods for handling time steps. The public 197 static worldTimeStep function simulates one time step for every Critter in the 198 critter collection (i.e., for the entire world). The abstract doTimeStep function simu199 lates the actions taken (if any) by a single critter as it goes about its life in the simulation. 200 Note that subclasses of Critter will override the doTimeStep function so that each type 201 of critter can behave in different ways (some will walk, some will run, some will stand 202 still, etc). 203 204 During a worldTimeStep you must accomplish all of the following tasks: 205 206 • Invoke the doTimeStep method on every living critter in the critter collection. 207 The phrase “living” critter is used here for completeness. Hopefully all the dead 208 critters are removed from your collection when they die. 209 • Some critters will implement their doTimeStep function by (in addition to oth210 er actions) walking or running. All of these critters must be moved to a new posi211 tion (see the description of the walk and run methods below). Once all critters 212 have moved in the time step, if two or more critters are occupying the same (x,y) 213 coordinates in the world (i.e., are in the same position) you must resolve the en214 counter between that pair of critters. At the end of that resolution, only one critter 215 will be permitted in any position. See encounter resolution below. If more than 216 two critters are in the same position, then you must resolve the encounters pair217 wise, but you may do so in an arbitrary sequence. For example, if A, B and C are 218 all critters in the same position, then you may first resolve the encounter between 219 A and B. If B remains alive and in the same position, then you may then resolve 220 the encounter between B and C (and so on, if there are more than three critters). 221 • [STAGE 2] Some critters will implement their doTimeStep function by (in ad222 dition to other actions) spawning offspring (i.e., calling the reproduce method, de223 scribed below). Once all critters have had their doTimeStep function called, 224 their movements applied, and all encounters resolved, then all new Critters 225 are added to the critter collection. Note that if a new critter is located in the same 226 position as an existing critter, you will not simulate an encounter. Any encounter 6/24/18 8:32 PM 6 227 will take place in the next time step (assuming the two critters remain in the same 228 position). 229 • Once all of the critters have been updated, with their doTimeStep functions in230 voked, their movement and encounters resolved and any offspring created, you 231 must cull the dead critters from the critter collection. Any critter whose energy 232 has dropped to zero or below during this time step is dead and should no longer be 233 part of the critter collection. Don’t forget to apply the 234 Params.rest_energy_cost to all critters before deciding if they are dead. 235 236 8. Walking and Running Critters: [run is a STAGE2 function, walk is STAGE1 237 During each time step, a critter may choose to invoke the walk or run function. These 238 functions are nearly identical, with the only difference being that walk will move a critter 239 one position in one of the eight directions, while run will move a critter two positions in 240 the specified direction. Note that while running, the critter must move in a straight line 241 (no zig-zags). Note also that a running critter will probably be charged more than twice as 242 much energy as a walking critter. The walk method must deduct 243 Params.walk_energy_cost from the critter that invokes it, and the run method 244 must deduce Params.run_energy_cost from the critter that invokes it. Since these 245 methods are so similar, you might want to minimize your code by sharing stuff between 246 these two. There will also be look functions added later that can further reuse your 247 code. 248 249 There are two critter methods that can call the walk and run methods. Most critters will 250 invoke the movement method directly from their doTimeStep function (the Craig 251 critter has this implementation). When invoked from this method, you must update the 252 energy for the Critter and calculate its new position. Recall that you will not check 253 for encounters until after all critters have moved. That means that two critters may tem254 porarily be located in the same position (Critter A moves on top of Critter B, but 255 then Critter B moves out of that position during the same time step) and/or that two 256 critters may move “through” each other (Critter A is directly to the left of Critter 257 B, Critter A moves one position to the right, Critter B moves one position to the 258 left). In neither of these situations will you simulate an encounter. 259 260 [STAGE 3] Note that critters cannot move twice from within the same doTimeStep 261 function. If a Critter subclass calls walk and/or run two (or more) times within a sin262 gle time step, you must deduct the appropriate energy cost from the critter for walk263 ing/running, but you must not actually alter the critter’s position. Critters can die in 264 this fashion. 265 266 [STAGE 3] Critters may also invoke walk or run from the fight() method. 267 You will call fight when you are resolving an encounter (see below). A critter that 268 does not want to fight can attempt to walk (or run) away. If a critter invokes walk or run 269 from inside its fight method, you must charge the appropriate energy cost (whether 270 you permit the critter to move or not). Then you will move the critter only if both of the 271 following conditions apply. 6/24/18 8:32 PM 7 272 1. The critter must not have attempted to move yet this time step. If the critter has 273 previously invoked either its walk or run method this time step, then it will not 274 move in fight (you’ll still penalize the critter with the movement cost, however). 275 2. The critter must not be moving into a position that is occupied by another critter. 276 Only if both of those conditions apply will you move the critter. In this case, the encoun277 ter is resolved and no fight will take place between the critters in the encounter (see be278 low). Note that if both critters attempt to move while resolving the encounter, and both 279 critters attempt to move into the same position, you should move only one of the two crit280 ters (you can arbitrarily move one, “first” and then the second critter will not be able to 281 move since that position is occupied). 282 283 9. Encounters Between Critters: [STAGE 2] 284 When two critters occupy the same position, an encounter must take place. Once all en285 counters are resolved, only a single critter can remain in any one position in the simula286 tion world. Recall that your simulator must detect and resolve encounters only after every 287 critter has had its doTimeStep method invoked (i.e., after every critter has had the op288 portunity to move). When you are resolving an encounter between critters A and B, you 289 should proceed as follows: 290 1. Invoke the A.fight(B.toString()) method to determine how A wants to 291 respond. Note that A may try to run away. Note that A may die trying to run away 292 (if it’s very low on energy). If the fight method returns true, then A wishes to at293 tempt to kill B. 294 2. Invoke the B.fight(A.toString()) method to determine how B wants to 295 respond. B may also try to run away. B may also die trying (both objects could 296 die!). If fight returns true then B wishes to attempt to kill B. 297 3. After both fight methods have been invoked, if A and B are both still alive, and 298 both still in the same position, then you must generate two random numbers (dice 299 rolls, see below). 300 a. If A elected to fight, then A rolls a number between 0 and A.energy. If 301 A did not decide to fight, then A rolls 0 302 b. If B elected to fight, then B rolls a number between 0 and B.energy. If 303 B did not decide to fight, then B rolls 0 304 The critter that rolls the higher number wins and survives the encounter. If 305 both critters roll the same number, then arbitrarily select a winner (e.g., A 306 wins). 307 4. If a critter loses a fight, then ½ of that loser’s energy is awarded to the winner of 308 the fight. The loser is dead and must be removed from the critter collection before 309 the end of this world time step. 310 311 [STAGE 3] Recall that if there are three or more critters in the same position, then the 312 encounters are resolved in an arbitrary sequence. If while resolving the encounter be313 tween A and B, both critters die or move out of the position, then you must not simulate 314 an encounter between A or B and any other critters in that position. For example, if A, B 315 and C are in the same position, and you simulate the encounter between A and B, and 316 both critters run away and move into new positions, then C will not encounter anything 6/24/18 8:32 PM 8 317 this time step. On the other hand, if A and B fight, and B wins (and gains energy from A), 318 then C will encounter (the newly strengthened) B critter. 319 320 10. Rolling Dice: 321 Critter provides a static function for generating uniformly-distributed random integers 322 within a specified range. The name of this function is Critter.getRandomInt and 323 you must use this function for generating any random numbers used in your simulation. 324 This rule applies to subclasses of Critter as well. For example, Craig calls Crit325 ter.getRandomInt as part of its doTimeStep function. Generating random num326 bers using any other method is disallowed for this project (We're worried that you might 327 have trouble making your simulation repeatable if we don’t constrain how random num328 bers are produced, so we're putting this restriction in the hopes that it will make your 329 lives easier in the long run). 330 331 11. Reproducing Critters: [STAGE 2] 332 Concrete subclasses of Critter may invoke the reproduce function. They can call 333 this function from either their doTimeStep function or from their fight function. In or334 der to call reproduce, the critter must first create a new Critter object (a new instance 335 of a concrete subclass of Critter) and pass a reference to this object to the reproduce 336 method. When that happens you must: 337 • Confirm that the “parent” critter has energy at least as large as 338 Params.min_reproduce_energy. If not, then your reproduce function 339 should return immediately. Naturally, the parent must not be dead (e.g., did not 340 lose a fight in the previous time step), but you should have removed any such crit341 ters from the critter collection and/or set their energy to zero anyway. 342 • Assign the child energy equal to ½ of the parent’s energy (rounding fractions 343 down). Reassign the parent so that it has ½ of its energy (rounding fraction up). 344 • Assign the child a position indicated by the parent’s current position and the spec345 ified direction. The child will always be created in a position immediately adja346 cent to the parent. If that position is occupied, put the child there anyway. The 347 child will not “encounter” any other critters this time step. 348 New “child” critters created during a time step are not added to the critter collection until 349 the end of the time step. They cannot prevent critter from walking (e.g., a critter wants to 350 walk away from an encounter, that critter cannot move into a position that’s already oc351 cupied by regular critter, but can move into a position occupied by a “newborn” critter), 352 and the new children cannot encounter any other critters this time step. All new children 353 will begin their existence within the simulated world in the next world time step. Note 354 that the parent’s reduction in energy happens immediately, however. 355 356 12. The Algae and TestCritter Subclasses:[STAGE 2] 357 Algae is a special critter type that can “cheat” – it can photosynthesize and is permitted 358 to spontaneously appear within the simulated world. Essentially, Algae acts as the food 359 supply for the other critters in the simulation. The Algae class is partially implemented 360 for you. The current implementation is based on the inner class Crit361 ter.TestCritter which has three “setter” methods defined. As you implement your 362 Critter class, you must ensure that these setter methods continue to work. For exam- 6/24/18 8:32 PM 9 363 ple, if you create an external data structure to represent the world “grid” (e.g., a two364 dimensional array of Critters), then the setX_coord and setY_coord functions 365 must update that external data structure correctly. Also, if the setEnergy setter is used 366 to make the critter’s energy go to zero (or become negative), then you must “kill” the 367 critter and remove it from the critter collection. 368 369 New Algae must be added to the world every time step. At the end of the time step, af370 ter all other activity has been simulated (all movements and encounters), use a loop to 371 create Params.refresh_algae_count new Algae. Each new Algae will have 372 Params.start_energy energy and will be assigned a random position. If the Al373 gae’s random position places the Algae in the same location as another critter, that is 374 OK. Newly created critters can be “on top of” other critters in the time step where they 375 are created, by the end of the next time step, however, the critters must move apart, or 376 they must fight (even Algae will fight if placed into the same location). 377 378 379 13. View Component: [STAGE 1] 380 The view (and controller) for this phase of the project is extremely rudimentary. We 381 won’t even bother pulling the “view” from the Critter class. Instead, your view con382 sists of implementing the public static displayWorld method. This function must 383 print a 2D grid to System.out. Each row in this grid represents one horizontal row in 384 the simulated world. Thus, there will be world_height such rows. Each row will have 385 world_width characters printed in it. If a position in the world is occupied then you 386 will print the toString() result for that critter in the corresponding row/column in 387 your output. If a position is not occupied, then you’ll print a single space. 388 389 You must also print a border around your text representation of the world. You must start 390 and end each row with a vertical bar “|” character, and you must include a row of dash “-“ 391 characters at the top and at the bottom of your diagram. Finally, the corners of your dia392 gram must have “+” characters. So, a small 5x5 world might look like this: 393 394 +-----+ 395 | @ C| 396 | | 397 | @ | 398 | @ | 399 |C @ | 400 +-----+ 401 402 Note that this world has 4 Algae critters and two Craig critters. Yeah, it’s pretty lame, 403 but we’ll look into building better graphics in phase 2 of the project. 404 405 14. Controller Component: 406 The controller for this phase is almost as rudimentary as the view, and is entirely text 407 based. You must use a Scanner object created in main() for reading from the keyboard. 408 Only one Scanner object connected to the keyboard may be created in the whole pro- 6/24/18 8:32 PM 10 409 gram. The controller must provide the end user with a prompt, “critters “. In re410 sponse to this prompt, the controller will accept a line of input (tabs and spaces do not 411 matter, but newline characters do, a newline marks the end of line). The following com412 mands are supported. All commands are case sensitive. 413 • quit – [STAGE 1] terminates the program 414 • show – [STAGE1] invoke the Critter.displayWorld() method 415 • step [ ] – [STAGE1] The is optional (count is [STAGE2]). If 416 is included, then will be an integer. There are no square brackets 417 in this command, this notation is used simply to indicate that the is op418 tional. For example, “step 10000” is a legal command, as is “step”. In response to 419 this command, the program must perform the specified number of world time 420 steps. If no count is provided, then only one world time step is performed. 421 • seed -- [STAGE2] invoke the Critter.setSeed method using 422 the number provided as the new random number seed. This method is provided so 423 that you can force your simulation to repeat the same sequence of random num424 bers during testing. 425 • make [ ] – [ STAGE3, for stages 1 and 2, edit your 426 main function so that 100 Algae and 25 Craig critters are always placed 427 into the world when it starts, for STAGE3, the world should start empty] as 428 before, the argument is optional. The command “make” must be provid429 ed verbatim. The argument will be a string and must be the name 430 of a concrete subclass of Critter. When this command is executed, the controller 431 will invoke the Critter.makeCritter static method. The 432 string will be provided as an argument to makeCritter. If no count is provid433 ed, then makeCritter will be called exactly once. If a count is provided, then 434 makeCritter will be called inside a loop the specified number of times. For 435 example “make Craig 25” will cause Crit436 ter.makeCritter(“Craig”); to be invoked 25 times. 437 • Note: The String passed in to the command and to MakeCritter is 438 the unqualified name of the Critter. Our starter code extracts the 439 package name, and you should prepend it to the class name as necessary. 440 441 • stats -- [STAGE3] Similar to make, must be a 442 string and will be the name of a concrete subclass of Critter. In response to this 443 command, the controller will 444 1. Invoke the Critter.getInstances() which must 445 return a java.util.List of all the instances of the spec446 ified class (including instances of subclasses) currently in the critter col447 lection – you must write Crittter.getInstances, by the way, we 448 didn’t provide that for you. 449 2. Invoke the static runStats() method for the specified class. For exam450 ple, if were Craig, then your controller will invoke 451 Craig.runStats() and will invoke this function with a list of all of 452 the Craig critters currently in the critter list. See the note about convert453 ing unqualified names to qualified. 6/24/18 8:32 PM 11 454 455 After processing the command, prompt the user for the next command. Naturally, if the 456 command is “quit”, then the program simply exits. 457 458 15. Exceptions and Errors: [STAGE3] 459 If any exception occurs for any reason while parsing or executing a command, your con460 troller must print one of the following error messages and continue executing. 461 • If a command is entered which does not match the list of commands above, then 462 your program must print: “invalid command: “ and then print the line of text en463 tered. For example, if I entered the command “exit now”, which is not a valid 464 command, your controller must print the error “invalid command: exit now” on a 465 single line. 466 • If an exception occurs during the execution of a command (e.g., InvalidCrit467 terException, or an exception while parsing an integer), then your program 468 must print, “error processing: “ and then print the line of text entered. For exam469 ple, if the command, “make Craig 10-“ would result in a parsing exception 470 because of the malformed 10- and must produce the output, “error pro471 cessing: make Craig 10-“ 472 • Note that any extraneous text or parsing error on the command line is treated as if 473 an exception occurred (whether one actually occurred or not). So, you treat 474 “make Craig blah” the same way you treat 475 “make Craig 10 blah” 476 477 16. Code Style: 478 You should have Javadoc style comments for all public, protected, and private methods 479 in your code that you have written or modified. There is no need to add Javadoc com480 ments to methods that already have such comments. Use good style, and provide com481 ments, braces, blank lines, and good variable names throughout your code. 482 Convert your comments to Javadoc html files (see Eclipse documentation), and submit 483 these HTML files in a docs folder along with the rest of your submission. We want sin484 gle page html files for each class – if that is not possible, contact us. In any case, this 485 part's format is somewhat flexible, as we will be grading these by eye. Don't convert the 486 html files to PDF before submission. 487 488 17. Grading: 489 We will be using a combination of JUNIT testing and running your main for grading. We 490 will also be inspecting your code by eye. We will be using a Linux server for our scripts, 491 but might switch to Eclipse, particularly in case of problems encountered with Linux. It 492 is your responsibility to see that your code works in both environments. We will explain 493 later how to run our JUNIT tests on the Linux server environment. 494 495 18. Presubmission Testing: 496 We have provided two test case files. Please follow the instructions on how to download 497 them to Eclipse and run them. 498 499 19. Submission: 6/24/18 8:32 PM 12 500 • Check in your files regularly into Git. We expect at least 4 substantial check-ins 501 from each team member. 502 • Each team should also provide a document team_plan.pdf describing the 503 work done by each of you. This document must include your Git repository URL. 504 Use the starter files provided on Canvas. 505 • Each team should also provide a README.pdf document describing your code 506 structure. 507 o Did you create any new classes, and if so, what fields and methods are in 508 it? 509 o What is the data structure that you used to hold your Critters? 510 o Be prepared to have a paper copy of this document during the recitation 511 section of the week the assignment is due. 512 • Name your critter source files Critter1.java, Critter2.java etc., and 513 include header comments with descriptions. Your toString() for these crit514 ters should be 1, 2 etc. I know this is not imaginative, but we need it for our 515 grader. 516 • Before submission, make sure that your main is cleaned up, so that it produces no 517 output to the console, and the Critter world is empty. 518 • Do not submit MyCritter1.java, MyCritter6.java etc. that we sup519 ply to you. 520 521 Before the deadline, one of you should submit a zip file with all your solution files. This 522 file should contain Critter.java, Main.java, your own Critters, and any 523 other files you created. Zip your source folder and other files together, and rename this 524 file (maybe initially called Archive.zip) Project4_EID1_EID2.zip. Omit 525 _EID2 if you are working alone. 526 527 To make the zip file, make a folder named Project4_EID1_EID2. Put the files in 528 there as per the diagram below. The invoke the Linux/MacOS command (or do the 529 equivalent in Windows): 530 zip –r Project4_EID1_EID2.zip Project4_EID1_EID2 531 532 Just to be sure, move your zip file to a different location and unzip it. 533 Make sure that the structure of the final ZIP file is as follows, when unzipped: 534 Project4_EID1_EID2/ (folder that is created by zip) 535 README.pdf 536 team_plan.pdf 537 538 docs/ 539 src/ 540 assignment4/ 541 Main.java 542 Critter.java 543 Critter1.java 544 Critter2.java 545 ... 6/24/18 8:32 PM 13 546 Good luck and have fun! 547 548 20. FAQ: 549 See the separate document on Canvas. 550 551 21. Before submission checklist: 552 ¨ Did you complete a header for *all* your files, with both your names and UT 553 EID's? 554 ¨ Did you mark the slip days used? 555 ¨ Did you do all the work by yourself or with your partner? 556 ¨ Did you zip all your new or changed files into a zip file? Did you remember not 557 to include the unchanged files that we provided? 558 ¨ Did you remove or comment out all the features that you added for testing that vi559 olate the rules of submission? 560 ¨ Did you include your own Critters, after testing them in your system? 561 ¨ Did you download your zipped file into a fresh folder, move it to the Linux serv562 er, make sure that your directory structure is exactly what we asked for, and run it 563 again to make sure everything is working? This is not optional. 564 ¨ Does your code work correctly on Eclipse with Java 8 as well as on the ECE 565 Linux server? 566 ¨ Is your package statement correct in all the files? 567 ¨ Did you preserve the directory structure? 568 ¨ Did you include a PDF document describing what each of you did on this project? 569 ¨ Did you include a PDF document with your code structure? 570 ¨ Did you include Javadoc files?

More products