Question: Java Images in computers are stored as two-dimensional arrays, each grid cell storing a number for a color. For this lab, we are going to
Java
Images in computers are stored as two-dimensional arrays, each grid cell storing a number for a color.
For this lab, we are going to create a class called Bitmap, which stores a simple black and white image.
Because different fonts display spaces at different widths, we are going to use a dash "-" for the white squares and the lowercase letter "o" for the black squares. If you are using DrJava, you can also change the output font to Courier New by going to the Edit menu, selecting Preferences -> Display Options -> Fonts, and setting the Main Font to Courier New.
Variables
String image[][] - A 10x10 two-dimensional array of Strings to hold the symbols. Because different fonts display spaces at different widths, we are going to use "-" for the white squares and "o" for the black squares.
Methods
Bitmap(int a[]) - This constructor initializes the images to all "-" symbols. The input parameter array has the coordinates of the "o" symbols listed as pairs. So elements a[0] and a[1] hold the coordinates for the row, column for the first "o", elements a[2] and element a[3] are the coordinates for the second "o", etc. Before processing, the constructor needs to check that all the coordinates listed in the array a are between 0 and 9 inclusive. The constructor also needs to check that the array consists of an even number of elements. This will ensure that there are no unmatched points. If either of these is not true, then the array should not have any "o" symbols stored.
public void flipHorizontal() - The "o" symbols in the array are flipped horizontally, or in others words, from left to right.
public void flipVertical() - The "o" symbols in the array are flipped vertically, or in other words, from top to bottom.
public void reverse() - Changes the "-" symbols to "o" symbols, and vice versa.
public String toString() - Returns a multiline String representing the image.
Please download the runner class student_Bitmap_runner.java and verify that the class output matches the sample run that follows. We will use a different runner to grade the program. Don't forget to change the runner to test different values to make sure your program fits the requirements.
Sample Run:
---------- -o-oo----- -oo--o---- -o----o--- oo----oo-- -o-o--o--- -o-o--o--- -o-o--o--- -oooooo--- ---------- after horizontal flip: ---------- -----oo-o- ----o--oo- ---o----o- --oo----oo ---o--o-o- ---o--o-o- ---o--o-o- ---oooooo- ---------- after vertical flip: ---------- -oooooo--- -o-o--o--- -o-o--o--- -o-o--o--- oo----oo-- -o----o--- -oo--o---- -o-oo----- ---------- after reverse flip: oooooooooo o-o--ooooo o--oo-oooo o-oooo-ooo --oooo--oo o-o-oo-ooo o-o-oo-ooo o-o-oo-ooo o------ooo oooooooooo
*****PLEASE FOLLOW INSTRUCTIONS EXACTLY*****
Thank you!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
