Programming Assignment 05/06
Due: Week of Oct. 3 in lab
Write a program to simulate a fish randomly swimming around an aquarium. Below are the details for the assignment:
- Your program takes in two command-line arguments. One for an input filename and one for an output filename.
-
The input file contains the state of the aquarium. Here is an
example. Details:
- The first line contains N the size of the aquarium (N x N).
- There are N lines following that, each with N characters.
- '.' is water.
- 'O' is an obstacle, like a rock.
- 'F' is the position of the fish. There will only be one 'F'.
-
Simulate 100 steps of a simulation. Draw the state of the tank at each
step. The rules:
- Put your name at the top left corner (left justified at (-1, N)) of the aquarium.
- Put your timestep at the bottom right corner (right justified at (N, -1)) of the aquarium.
- The ocean is blue. Draw white lines to show the grid cells appropriately.
- Obstacles are black circles (they should visibly be within a grid cell).
- Download a pretty picture for the fish. Show it as the size of a single grid cell, or a little smaller.
- The canvas is 500x500 pixels.
- The X scale and Y scale are both (-1.5, N+0.5).
- The fish randomly moves one cell east, south, west, or north.
- The fish cannot move out of the tank.
- The fish cannot move into an obstacle.
- The fish must move each time step, it cannot sit still.
- Pause for 100ms.
- Remember that in order to draw the matrix from the file, that columns are X coordinates (not Y), rows are Y coordinates (not X), and rows should start from the top (not bottom)
- At the end of the simulation write the state of the tank to the output filename specified in the same format as the input.
-
Your program should be called
aquarium.java
. Implement your code using functions (static methods). Some ideas on how to organize your code into functions (these are not required only thoughts on the top of my head):ReadInputFile
- A function that takes a parameter of aString
and creates the aquarium multiarray from the information in the file.WriteOutputFile
- A function that takes parameters of aString
and the aquarium multiarray and writes the multiarray to a file.MoveFish
- A function that takes as input the position (row and column) of the fish and the multiarray and relocates the fish to a new location.DrawGrid
- A function that takes N the size of the aquarium and draws the grid lines.DrawObstacles
- A function that takes the multiarray of the tank, searches for, and draws the obstacles.- Etc.
Press play to show example video. Note the video is stretched
width-wise and is not representative of the real example program.
Bonus. Add a shark to the aquarium. Details:
- It will be denoted as an 'S' in the input and output files.
- The shark randomly moves every other timestep. The shark moves after the fish and cannot occupy the same cell as the fish.
- The shark can only eat the fish if it is not moving (the fish runs into the shark).
This assignment will be graded as two separate programming assignments. Part one of the grade focuses on the final product. Did you pay attention to detail and implement the simulation/drawing as specified. Part two of the grade is focused on implementing components of the program into functions. Each portion is graded out of 100 points.
Grading
Each assignment is graded out of 100% based on a combination of the criteria listed in the assignment description and programming style (e.g., good comments and naming) -- following instructions is extremely important in computer science, train yourself to think like the computer; programming style is important to be able to communicate your solutions to another programmer; both of which you are graded upon.
Specific instructions. Failure to do these steps will result in a loss of points.
- Name each file and program as listed in the instructions.
- Name all variables descriptively.
- Indent all programs appropriately.
- Use comments to help explain the steps and logic of your program.
- The top of your program should have a comment block where the first line
is your name, second line is your section, and third line is a description
of your java program.
//Name: Jory Denny
//Section: 00
//This program debates Batman vs Superman!
Turn in instructions. Each programming assignment is to be turned in before your lab section. You will turn in a soft copy of the assignment (.java or .zip for multiple java files) through blackboard. You will also turn in a hard copy of the assignment in your lab section with a signed coverpage (each program should start a new page of the hard copy).
If there are any discrepencies in grades please see the instructor during his office hours or by appointment (do not discuss with the lab assistants or graders).