$28
PROGRAMMING II
Pair Programming is HIGHLY encouraged for this assignment.
This assignment involves extending your P3 Swim Sim (Classes) program to load initial object locations from a file, and to appropriately handle a variety of problems that might occur throughout that process. In addition to this new functionality, your P4 submission will be graded by humans looking for clarity, appropriate use of java constructs, and adherence to the CS300 Course Style Guide. Objectives and Grading Criteria The goals of this assignment include gaining experience with exception handling, and loading data from files. You will also gain experience reviewing code for clarity, and improving code clarity in a variety of ways. Grade Breakdown: 10 points 2 zyBooks Tests: automated grading test results are visible upon submission, and allow multiple opportunities to correct the organization and functionality of your code. Your highest scoring submission prior to the deadline will be recorded. 15 points 3 Hidden Tests: automated grading tests are run after the assignment’s deadline. They check for similar functionality and organizational correctness as the zyBooks Tests. But P4: SWIMSIM (EXCEPTIONAL) LECTURE NOTES you will NOT be able to resubmit corrections for extra points, and should therefore consider and test your own code even more thoroughly. 10 points Final Submission Commenting: human graders will review the comments in your final submission. They will be looking for clear comments that conform to the CS300 Course Style Guide and improve the readability of your code. 15 points Final Submission Style and Organization: human graders will review the style and organization of your final submission. They will be looking for clear and consistent style that both makes appropriate use of java constructs and conforms to the CS300 Course Style Guide. GETTING STARTED 0. If it’s not already there, open the project containing your P3 code in Eclipse. Make a copy of this project and name this copy whatever you’d like, although P4SwimSim would be a descriptive choice. 1. We’ll need to be able to instantiate new objects initialized to non-random specified positions in this assignment. To accomplish this, overload the constructors in your Fish, Food, and Hook classes to take additional starting x and y position parameters. The order of parameters in each of these constructors should become: PApplet processing, int x, int y. Try testing out these new constructors to help ensure that they work before proceeding through the next steps. 2. The rest of the functionality changes for this programming assignment should be confined to private helper methods within your SwimSimulation class. You are responsible for organizing your implementation of these features. The file format specifications below are followed by specifications for how your program should respond to several different kinds of potential problems. Reading through these specifications before writing any code is recommended for this assignment. FILE FORMATS 3. There are two plain text file formats that your program will make use of for this assignment. The first file format is .ssf (SwimSimFiles), which contains a list of possible files (relative paths) to load. One of these files will be chosen at random by your program, and then loaded to initialize your simulation’s objects and their starting positions. This second file format is .ssd (SwimSimData), which contains specifications for both the number of objects of each type that your simulation should contain, and the starting positions for each object. 4. Your program should expect to find a single .ssf file named FileOptions.ssf within the working directory that your program is executed from. By default, this will be within your project folder in Eclipse. However a simple test to check this location can be performed by printing out the absolute path of a folder referenced using the path period (a relative path referencing the current working directory). 5. You can create your own .ssf file or use the example here. You’ll want to test your code against different variations of this file to make sure they all work. Each .ssf file should contain a list of one or more relative file paths separated by a single semicolons (;) and possibly additional whitespace (spaces, tabs, and newlines). The file separators in these paths may be either forward slashes (/) or backward slashes (\) which may need to be converted to the File.separatorChar sequence of the current system. Some of the string methods that may be helpful in working with these paths include: trim() – returns a new string without the leading or trailing whitespace of the original split(“;”) – returns an array of strings containing the parts of the original separated by semicolons replace(‘\\’,File.separatorChar).replace(‘/’,File.separatorChar) – returns a new string with all slashes replaced by system specific path separator characters 6. For .ssd SwimSimData files, you can create your own and also use the examples here, here, and here. You’ll want to test your code against different variations of these files to make sure they all work. Each .ssd file is composed of three sections which can appear in any order, one section describing the Fish, one for the Food, and one for the Hook. Each section starts with a header (all one one line) containing one of those three type names (with any capitalization), followed by a single colon (:), and then the integer number of objects of that type that your simulation should contain. Following this header will be the initial positions for each object of that type. Each position will be on its own line, and will contain an integer x-position, followed by a comma, followed by an integer y-position. Additional tabs and spaces may appear anywhere in the file that is not in the middle of an integer or type name. And additional blank lines may also be present anywhere in any .ssd file. EXCEPTIONAL CIRCUMSTANCES 7. In addition to familiarizing yourself with the file formats described above, it will be helpful to understand how your program should behave in a variety of situations described below: When both files exist and conform to the format specifications above, your program should begin running a normal simulation with the specified number of objects of each type at the specified starting positions. 1 System.out.println( new File(".").getAbsolutePath() ); When there is no accessible file named “FileOptions.ssf” within the working directory, your program should print the following error message (to System.out): “WARNING: Could not find or open the FileOptions.ssf file.”, and then load and run a the simulation with four fish, six food, and one hook all at random locations. When “FileOptions.ssf” is accessible but the randomly chosen .ssd file path references an inaccessible file, your program should print the following error message (to System.out): “WARNING: Could not find or open the file.” Where is replaced by the randomly chosen path that your program was unable to read a file from. Your program should then load and run a simulation with four fish, six food, and one hook all at random locations. When both the “FileOptions.ssf” file and the randomly chose .ssd file path are both accessible, but there is a problem with the contents of the .ssd file, your program should print one of the following error messages (to System.out) before loading and running the simulation with four fish, six food, and one hook all at random locations. “WARNING: Number of does not match number of positions.” where is either FISH, FOOD, or HOOK and the number of positions in the file does not match the integer from that section’s header. “WARNING: Missing specification for the number and initial positions of fishes, foods, or hook.” when any of the three sections is missing from the randomly chosen .ssd file. “WARNING: Failed to load objects and positions from file.” when any other problems are found related to the with the format or loading of these files. 8. Note that none of the previously assigned methods should be throwing any checked exceptions, and that the only methods that may throw any checked exceptions are your own private helper methods. You code is not required to throw any exceptions, but if you do choose to do this, the java.util.zip.DataFormatException type may be a useful type for this purpose. CODE REVIEW 9. After implementing and testing this new functionality within your simulation, you should perform a code review of this code. If you are working with a partner, I suggest adding the new features from this assignment into each of your individual P3 programs. Then exchange programs and review each others’ work looking both for things that are communicated very clearly and for things that present some confusion. You can then compare your lists of pros and cons to merge the best features of each implementation together, and hopefully even improve on that. 10. Be sure to familiarize yourself with the CS300 Course Style Guide. An extra section was recently added to this guide, with tips for using Eclipse to help style your code. Remember that this document contains minimal requirements for your code, and that there are likely many more specific and more helpful ways to improve the readability of your code. There are likely to be many complex trade-offs with no single correct solution, please discuss these with your partner and with your classmates via piazza (without posting code from your assignment). Our grading rubric for this assignment is focused on detecting design decisions that have either been neglected, or that reflect a misunderstanding of the intended use for some java constructs. 11. Congratulations on finishing this fourth CS300 assignment! After verifying that your work is correct, and written clearly in a style that is consistent with the course style guide, you should submit your work through zybooks. If the automated tests detect defects in your code, you may fix those and re-submit for full credit, although you will need to wait an hour between submissions. The most recent of your highest scoring submissions prior to the deadline of 17:00 on Thursday, October 5th will be used as part of your score for this assignment. Additional grading tests and review by human graders will then be performed on that most recent of your highest scoring submission to determine the rest of your P4 grade.