Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a bridges.base.ColorGrid in Java with a Point class and a draw method. 7. The Point class A Point object represents a single pixel, at

Write a bridges.base.ColorGrid in Java with a Point class and a draw method.image text in transcribedimage text in transcribed

7. The Point class A Point object represents a single pixel, at a particular coordinate, of a particular color. Point is a kind of Mark, so the point class is a subclass of the class Mark. Since Mark has an abstract method called draw, your Point class must define a draw method. 7.1. Constructor Complete the constructor, which is started for you in the Point class. Your Point will need to remember x, y, and color when its draw method is called. Therefore, you need instance variables. Note that you do not need to include an instance variable for color because Mark already declares one for its subclasses to use. But you do need to initialize color in the Point constructor Tip: In this assignment, make all your instance variables private. There is no need for code outside the class to access them. 7.2. draw method Draw takes a ColorGrid as its only argument, and it draws a pixel onto the ColorGrid. Only one argument? But where do I get the location of the pixel and its color? That's why you kept this information in the Point class's instance variables! What is a ColorGrid? A ColorGrid represents an integer coordinate space of a given height (number of horizontal rows) and width (number of vertical columns). Think of it like a digital canvas. Each cell of the space stores the color of a pixel at that coordinate. The axes can also be called x (which column?) and y (which row?). The origin is in the upper-left and the coordinates increase down and to the right. Given a ColorGrid cg, the following code sets certain pixels. import bridges.base. Color; import bridges.base. ColorGrid; public class Point extends Mark { public Point(int x, int y, Color c) { } @Override public void draw(ColorGrid cg) { } } 7. The Point class A Point object represents a single pixel, at a particular coordinate, of a particular color. Point is a kind of Mark, so the point class is a subclass of the class Mark. Since Mark has an abstract method called draw, your Point class must define a draw method. 7.1. Constructor Complete the constructor, which is started for you in the Point class. Your Point will need to remember x, y, and color when its draw method is called. Therefore, you need instance variables. Note that you do not need to include an instance variable for color because Mark already declares one for its subclasses to use. But you do need to initialize color in the Point constructor Tip: In this assignment, make all your instance variables private. There is no need for code outside the class to access them. 7.2. draw method Draw takes a ColorGrid as its only argument, and it draws a pixel onto the ColorGrid. Only one argument? But where do I get the location of the pixel and its color? That's why you kept this information in the Point class's instance variables! What is a ColorGrid? A ColorGrid represents an integer coordinate space of a given height (number of horizontal rows) and width (number of vertical columns). Think of it like a digital canvas. Each cell of the space stores the color of a pixel at that coordinate. The axes can also be called x (which column?) and y (which row?). The origin is in the upper-left and the coordinates increase down and to the right. Given a ColorGrid cg, the following code sets certain pixels. import bridges.base. Color; import bridges.base. ColorGrid; public class Point extends Mark { public Point(int x, int y, Color c) { } @Override public void draw(ColorGrid cg) { } }

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_2

Step: 3

blur-text-image_3

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

Practical Neo4j

Authors: Gregory Jordan

1st Edition

1484200225, 9781484200223

More Books

Students also viewed these Databases questions

Question

Discuss the states of accounting

Answered: 1 week ago

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago