AP Computer Science I
Java Lab Unit Assignment # 14
The Practice FishGfx Program
70, 80, 90, 100 & 110 Point Versions
Assignment Purpose: The purpose of this assignment is to review OOP and control structures with a provided FishGfx class. The program also practices two-dimensional array manipulation and will be a good prelude to the Marine Biology Case Study. Write a program that uses a provided FishGfx class. This class facilitates drawing small graphics fishes on a two-dimensional "fish tank" simulation. The provided FishGfx bytecode file allows drawing fish and erasing fish in the fish tank without understanding or even knowing how the FishGfx class methods are implemented. A partial FishGfx.java file is shown below, which provides the interface information that is needed to use the class methods. // FishGfx.java // This is a partial source code file of the FishGfx class. // Only the available method headings are shown. All implementations are hidden. import java.awt.*; class FishGfx { private void delay(double n) // This method delays program execution where N is roughly the number of mili-seconds // of the delay. This method is called after DrawFish and EraseFish. // The only purpose of this method is to view the fish as they are drawn and erased. private Color getColor(int clr) // returns the following colors for integer parameter clr: // 1 red; // 2 green; // 3 blue; // 4 orange; // 5 cyan; // 6 magenta; // 7 yellow; // 8 pink; // 9 black; private void drawGrid(Graphics g, int l, int w) // draws a two-dimensional grid with l x w (Length x Width) fish locations public FishGfx(Graphics g, int rows, int cols, double td) // constructs a fishgfx object with specified dimensions and time delay public void drawFish(Graphics g, int row, int col, int clr, int num) // draws a fish at the specified [row][col] grid location with color (clr) and a number(num) // to identify the fish public void eraseFish(Graphics g, int row, int col) // erases a fish at the specified row X col grid location // an intentional time delay is called at the conclusion
Lab 14 Page 1 1/11/2006
Lab14st.java
Provided student file
// Lab14st.java // The FishGfx Program // Student Version import java.awt.*; public class Lab14st extends java.applet.Applet { public void paint(Graphics g) { FishGfx fish = new FishGfx(g,20,20,2000); } }
Student Version Output
You start with what is essentially an empty 20 by 20 fish tank.
70 Point Version Specifics Lab 14 Page 2 1/11/2006
For the 70-point version you need to write a program that draws fish on a 20 x 20 fish tank grid. It will be necessary to have a monitor setting of 1024 X 768 to view the entire tank without scrolling. The fish need to be drawn with consecutive numbers from 1 to 400 with a time delay that simulates some movement. Fish(1) starts at the [0][0] grid location in the top-left corner. From then on, fish are drawn moving from left-to-right, row after row. All fish are the same color. The fish are never erased. The statement below shows a call to the drawFish method.
fish.drawFish(g,row,col,clr,count));
70 Point Version Output
Lab 14 Page 3 1/11/2006
80 Point Version Specifics The 80-point version requires everything from the 70-point version, but the pattern of fish is a little more complicated. Fish(1) still starts at the [0][0] grid location in the top-left corner. From then on, fish are drawn moving from left-to-right. However, on the next row the fish move from right-to-left. The fish keep changing direction on each row.
80 Point Version Output
Lab 14 Page 4 1/11/2006
90 Point Version Specifics The 90-point version requires a more complicated pattern than the 70 or 80-point versions. Fish(1) still starts at the [0][0] grid location in the top-left corner. From then on the fish are drawn in a CLOCKWISE spiral-like pattern working its way to the center.
90 Point Version Output
Lab 14 Page 5 1/11/2006
Extra Points One way to earn 10 extra points is to erase the fish after they are all drawn. The fish need to be erased in the same sequence they were drawn. Another way to earn 10 extra points is to have multiple colors for the fish. This does not mean that every fish is a different color from the one next to it. Here are the color rules: 1) 2) 3)
All of the first in the top row are red (color 1). Whenever a new row (or column) is started, the color is advanced to the next one. After color 9 is used, the color needs to start over at 1.
A total of 20 extra points can be earned for doing both of these. This means the 70-point version can be worth as much as a 90; the 80-point version can be worth as much as a 100; and the 90-point version can be worth as much as a 110. What will now be shown are a couple examples of 100 and 110 point programs
90 or 100 (if it erases) Point Version Output
Lab 14 Page 6 1/11/2006
100 or 110 (if it erases) Point Version Output
Lab 14 Page 7 1/11/2006