Question: Please show the Java code for this problem Problem 1 : TextCanvas 1 0 0 pts Implement a TextCanvas class in chapter 1 0 .

Please show the Java code for this problem
Problem 1: TextCanvas
100 pts
Implement a TextCanvas class in chapter10.canvas package. The TextCanvas class should implement Canvas package as provided in the assignment.
package chapter10.canvas;
/**
* The implementing class should have a constructor with two parameters
* width: the width of the canvas.
* height: the height of the canvas.
*
* The valid locations for each pixels are from [0..height-1][0..width-1]
*
*/
public interface Canvas {
/**
* returns the height of the canvas.
*/
int getHeight();
/**
* returns the width of the canvas.
*/
int getWidth();
/**
* @param an rectangle area to be added to the canvas
* returns the id of the rectangle in the canvas. The id of the
* rectangle is a unique integer for a rectangle in the canvas, and
* id will not be reused(after the deletion of a rectangle).
*
* If the coordinates are not valid or out of the bounds for the canvas,
* returns -1.
*/
int add(int leftX, int upperY, int rightX, int bottomY);
/**
* removes the rectangle identified by the id from the canvas.
*/
int remove(int id);
/**
* moves the rectangle identified by id to the right by xOff and down by yOff.
* If the move attempt to move the rectangle out of bounds of the canvas,
* the rectangle will stop at the boundary.
*
* If xOff is a negative number, move to the left by |xOff|.
* If yOff is a negative number, move up by |yOff|,
*/
int move(int id, int xOff, int yOff);
/**
* returns the total shaded area on this canvas.
*/
int getShadedArea();
/**
* displays the convas. Each pixel on the canvas will be displayed as a
* blank if it is not covered by any rectangles, and will be displayed as
* a star if it is covered by one or more rectangles.
*/
void draw();
}
import chapter10.canvas.Canvas;
import chapter10.canvas.TextCanvas;
public class TextCanvasTest {
public static void main(String[] args){
Canvas canvas = new TextCanvas(30,20);
int r1= canvas.add(0,6,6,9);
int r2= canvas.add(4,4,8,8);
canvas.draw();
System.out.println(canvas.getShadedArea());
canvas.remove(r1);
canvas.move(r2,-5,-2);
canvas.draw();
// this rectangle is out of bound, and will not be added
canvas.add(0,2,30,20);
System.out.println(canvas.getShadedArea());
canvas.draw();
}
}
Please show the Java code for this problem

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!