Part A: (ungraded) Read Chapter 10. Do exercises 5, 7, 11, 15. Write and run a JAVA program to check your answers. You are permitted to work together on any ungraded work for the course.
Part B: [5 points] Write a general description of the purpose of each method that you will use when writing program pg6. If you are planning a multiple class solution (object oriented - highly recommended), also clarify which class each method belongs in. Your solution should probably have at least 4 methods plus main. You do not have to include the method headers, javadocs or any implementation details. The purpose is to start thinking about how to break the problem down into smaller chunks.
Part A: Snake Box [40 pts]
This week we are going to use arrays of characters to represent a two dimensional box of snakes and write a program that automates finding and skinning them, one by one. When a snake is skinned, its body is destoyed, leaving only the skin in the same position where the whole snake once was. In our box, the '+' character will represent a wall, the 'S' character will represent a link in a snake's body, and '.' will represent a link in a snake's skin after the body has been found and destroyed. All other positions will be spaces.
Initial snake boxes will be read from plain text files. You can assume that each file contains the size of the box (number of rows and columns) and the number of snakes in the box as the first line of data. Subsequent file lines contain the actual characters that make up the snake box. A snake can be identified by a continuous chain of 'S's and you can assume that no two snakes intersect or overlap each other. Any two links of a snake can be adjacent horizontally, vertically, or diagonally. Each link can have at most 2 neighbors so that the chain of links is unambiguous. Two sample files have been created for you: snakes1.txt and snakes2.txt, but you should create more for testing purposes.
Your program must have the following sequential operation:
[6 pts] You are strongly encouraged but not required to do an object oriented solution to this problem. Everything can be in one class with main, or you can create a SnakeBox class in addition to the main class. However, regardless of how many classes are involved, you must use methods to handle the various operations of the program, and include proper javadoc comments for all methods. Also try to avoid using any global variables. You must submit all *.java files in your solution as a zipped file on Blackboard. Print all *.java files as well.
Optional Part B: Snake Box [20 pts extra credit] -- due 1pm Monday, 4/8Write a program that will randomly generate a snake box according to dimensions input by the user. As in pg6a, use '+' to create walls for the edges of the box, and 'S' to represent links in each snake. Do error checking to make sure that the user inputs at least 5 as the row and column sizes, which will include the surrounding walls.
Each snake must have a clear unambiguous chain of S links, which means that each S can have at most 2 neighboring Ss. As in pg6a, the neighbors could be in horizontal, vertical, or diagonal directions. Display your snake box on the screen. You do not have to count the number of snakes in the box. (Hint: don't try to randomly generate one snake at a time, just randomly put Ss in the box according to the rules.)
Since this is extra credit, there is no late grace period for blackboard submission, and we will not collect printouts. You should use methods and javadoc in your solution. Name your file with main pg6b.java.
General assignment requirements, style and submission details: