Question: JAVA program: 1. Declare a class Drawing with the following members: a. Constructor initializes/fills a 2D array of characters with - (See snapshot in next
JAVA program:
1. Declare a class Drawing with the following members:
a. Constructor
initializes/fills a 2D array of characters with - (See snapshot in next page)
takes as input 2 integers (rows, cols) for the array
double arrays in Java:
char[][] arr = new char[rows][cols];
b. draw() prints the 2D array of characters on the screen
2. Define an abstract class Figure, with the following members:
a. Drawing class (has-a/Composition relationship)
b. point (x, y) - every Figure needs at least one point.
c. Constructor
i. Initializes the point
ii. Gets the rows and cols as input (from the user) and Initializes the Drawing array/map [to all -]
d. An abstract method computeSurface()
e. A method draw()
3. Define a class Rectangle that inherits from Figure, with the following members:
a. Width
b. Length
c. Appropriate constructor
i. Calls the super constructor
d. Override the inherited abstract computeSurface()
e. Override/Overload the inherited draw()
Program Execution:
Instantiate a Drawing object, and ask the user for the rows and columns numbers, then call the draw() method of the Drawing class. See next execution sample. At this stage, you are checking that your Drawing is settled! (No Rectangle is created yet).
2. Ask the user to enter Rectangle width and length, and the upper-left point coordinates.
3. Call the Rectangle constructor (that you defined!).
This should call the super constructor
4. Call the draw() method of the Rectangle
We assume that Rectangles are always drawn in parallel to the X and Y axis, i.e., you dont need the other 3 points. Width and Length are sufficient to draw the Rectangle. See next execution snapshot.
5. Call the computeSurface() method of the Rectangle.
Note, in the example above, that we consider the upper-left array point is (0, 0) and the lower-right point is (20, 40)
Kterminated mainClass (2) Java Application] C:\Prograr COSC 1430 GA 4 Enter Rows 20 Enter Cols: Enter Rectangle coordinates (x, y) Enter Recatangle width: Enter Recatangle length: 10 Surface: 50 Good Will
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
