Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

My assignment, my code, and my error statements are below. Please help! Thanks so much in advance!! These are my errors: Your code has been

My assignment, my code, and my error statements are below. Please help! Thanks so much in advance!! These are my errors: Your code has been evaluated against a set of test data. You had 2 out of 6 tests pass correctly. Your score is 33%. The tests that failed were: Test 1: Creating bitmap image with a valid set of input data Incorrect: toString() Output Test 2: Calling flipHorizontal() on the existing image Incorrect: toString() Output Test 3: Calling flipVertical() on the existing image Incorrect: toString() Output Test 4: Calling reverse() on the existing image Incorrect: toString() Output 
Assignment 7 - Bitmap 

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

NOTE: You MUST use the class name "Bitmap" for this assignment. REMEMBER: you must SUBMIT your answer. Your assignment doesn't count as complete unless it has been submitted.

This is what I have currently: public class Bitmap { String image[][] = new String[10][10]; int dah = 0; public Bitmap(int a[]){ for (int i = 0; i < 10; i++){ for (int j = 0; j < 10; j++){ image[i][j] = "-"; } } if (a.length %2 == 0){ for (int d = 0; d < a.length; d++){ if ((a[d] > 9) || (a[d] < 0)){ dah = 1; } } }else{ dah = 1; } for (int q = 0; q+1 < a.length; q+=2){ if (dah == 0){ image[a[q]][a[q+1]] = "*"; } } } public void flipVertical(){ String roh[] = new String[10]; int death = 0; int doom = 9; while ((doom >= 4) && (death <= 5)){ for (int i = 0; i < 10; i++){ roh[i] = image[death][i]; image[death][i] = image[doom][i]; image[doom][i] = roh[i]; } doom--; death++; } } public void flipHorizontal(){ String s[] = new String[10]; int death = 0; int doom = 9; while (doom >= 4){ for (int i = 0; i < 10; i++){ s[i] = image[i][death]; image[i][death] = image[i][doom]; image[i][doom] = s[i]; } doom--; death++; } } public void reverse(){ for (int i = 0; i < 10; i++){ for (int j = 0; j < 10; j++){ if (image[i][j].equals("-")){ image[i][j] = "*"; }else{ image[i][j] = "-"; } } } } public String toString(){ String fus = ""; fus = " "; fus = ""; for (int i = 0; i < 10; i++){ for (int j = 0; j < 10; j++){ fus = fus+image[i][j]; } fus = fus + " "; } return fus; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Systems Analysis And Synthesis Bridging Computer Science And Information Technology

Authors: Barry Dwyer

1st Edition

0128054492, 9780128054499

Students also viewed these Databases questions

Question

What are the most useful methods of initial selection?

Answered: 1 week ago

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago