Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you help creating the classes ? The classes shown in black are included in the skeleton project. You must complete the project by writing

Can you help creating the classes ?

The classes shown in black are included in the skeleton project. You must complete the project

by writing those classes shown in red and modifying the Parser class so that it will parse the

expanded grammar. Below is a description of each of the five classes that you must write:

The Text class must contain a constructor that is supplied the color that defines the text color, a

point that specifies the text location and a string containing the text to be displayed. It must also

contain a draw function because it is extends the abstract class Image. The draw function must

draw the text using the method drawString in Graphics class.

The SolidPolygon class must contain a constructor that is passed the number of vertices in the

polygon and its color. It must define the method drawPolygon because it is extends the abstract

class Polygon_. It should call the fillPolygon method of the Graphics class to draw a solid

polygon.

The IsoscelesTriangle class must have a constructor that is supplied the color of the triangle,

a point that specifies the location of the top vertex, and the height and width of the triangle. It

must allocate the arrays of x and y coordinates that defines the triangle and it must compute their

values.

The Parallelogram class must have a constructor that is supplied the color of the parallelogram,

two points that specifies the location of the upper left and lower right vertices in addition to

an x offset value that specifies the x distance between the upper and lower left vertices. It must

allocate the arrays of x and y coordinates that defines the parallelogram and it must compute their

values.

The RegularPolygon class must contain a constructor that is supplied the color of the polygon,

the number of sides, a point that specifies the location of its center, and the radius, which defines

the distance between the center and each of the vertices. It must allocate the arrays of x and y

coordinates that defines the regular polygon and it must compute their values.

Below is a sample of a scene definition file that would provide input to the program:

Scene Polygons (500, 500)

RightTriangle Color (255, 0, 0) at (50, 30) Height 100 Width 300;

Rectangle Color (0, 128, 255) at (100, 100) Height 200 Width 100;

Isosceles Color (255, 0, 0) at (120, 120) Height 100 Width 200;

Parallelogram Color (0, 0, 255) at (340, 50) (440, 120) Offset 30;

RegularPolygon Color(255, 0, 255) at (300, 300) Sides 6 Radius 80;

Text Color(0, 0, 0) at (400, 200) "Hello World";

End.

//parallelogram

else if (imageToken == Token.PARALLELOGRAM) {

verifyNextToken(Token.OFFSET);

verifyNextToken(Token.NUMBER);

offset = lexer.getNumber();

Parallelogram parallelogram = new Parallelogram (color, point, point, offset);

scene.addImage(parallelogram);

}

// regular_polygon

else if (imageToken == Token.REGULAR_POLYGON) {

verifyNextToken(Token.SIDES);

verifyNextToken(Token.NUMBER);

sides = lexer.getNumber();

verifyNextToken(Token.RADIUS);

verifyNextToken(Token.NUMBER);

radius = lexer.getNumber();

Regular_polygon regular_polygon = new Regular_polygon (color, point, sides, radius);

scene.addImage(regular_polygon);

}

//isosceles

else if (imageToken == Token.ISOSCELES) {

verifyNextToken(Token.HEIGHT);

verifyNextToken(Token.NUMBER);

height = lexer.getNumber();

verifyNextToken(Token.WIDTH);

verifyNextToken(Token.NUMBER);

width = lexer.getNumber();

Isosceles isosceles = new Isosceles (color, point, height, width);

scene.addImage(isosceles);

}

//text

else if (imageToken ==Token.TEXT){

verifyNextToken(Token.STRING);

strTextDisplay = lexer.getLexeme();

Text text = new Text (color, point, strTextDisplay);

scene.addImage(text);

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

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions

Question

What are the purposes of collection messages? (Objective 5)

Answered: 1 week ago