Question: Please read everything I am having some trouble with this assignment, I created the addition to parser, and the text class however Its not working.

Please read everything I am having some trouble with this assignment, I created the addition to parser, and the text class however Its not working.

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.Please read everything I am having some trouble with this assignment, I

My Text class is

import java.awt.*; public class Text extends Image { public Color color; public Point position; public String text; public Text(Color color, Point upperLeft, String text) { super(color); this.text = text; } public void draw(Graphics g) { g.setColor(this.color); g.drawString(this.text, this.position.x, this.position.y); } } 

My parser class that was edited to have the "String Text"

 private void parseImages(Scene scene, Token imageToken) throws LexicalError, SyntaxError, IOException { int height, width, offset, radius; verifyNextToken(Token.COLOR); int[] colors = getNumberList(3); Color color = new Color(colors[0], colors[1], colors[2]); verifyNextToken(Token.AT); int[] location = getNumberList(2); Point point = new Point(location[0], location[1]); String string = new String(""); if (imageToken == Token.RIGHT_TRIANGLE) { verifyNextToken(Token.HEIGHT); verifyNextToken(Token.NUMBER); height = lexer.getNumber(); verifyNextToken(Token.WIDTH); verifyNextToken(Token.NUMBER); width = lexer.getNumber(); RightTriangle triangle = new RightTriangle(color, point, height, width); scene.addImage(triangle); } else if (imageToken == Token.RECTANGLE) { verifyNextToken(Token.HEIGHT); verifyNextToken(Token.NUMBER); height = lexer.getNumber(); verifyNextToken(Token.WIDTH); verifyNextToken(Token.NUMBER); width = lexer.getNumber(); Rectangle rectangle = new Rectangle(color, point, height, width); scene.addImage(rectangle); } else if (imageToken == Token.ISOSCELES_TRIANGLE) { verifyNextToken(Token.HEIGHT); verifyNextToken(Token.NUMBER); height = lexer.getNumber(); verifyNextToken(Token.WIDTH); verifyNextToken(Token.NUMBER); width = lexer.getNumber(); IsoscelesTriangle isosceles = new IsoscelesTriangle(color, point, height, width); scene.addImage(isosceles); } else if (imageToken == Token.TEXT) { string = lexer.getLexMe(); Text text = new Text(color, point, string); scene.addImage(text); } else { throw new SyntaxError(lexer.getLineNo(), "Unexpected image name " + imageToken); } verifyNextToken(Token.SEMICOLON); token = lexer.getNextToken(); if (token != Token.END) parseImages(scene, token); } // Parses the following productions // number_list -> '(' numbers ')' // numbers -> NUMBER | NUMBER ',' numbers // Returns an array of the numbers in the number list private int[] getNumberList(int count) throws LexicalError, SyntaxError, IOException { int[] list = new int[count]; verifyNextToken(Token.LEFT_PAREN); for (int i = 0; i  list = new ArrayList(); verifyNextToken(Token.LEFT_PAREN); do { verifyNextToken(Token.NUMBER); list.add((int) lexer.getNumber()); token = lexer.getNextToken(); } while (token == Token.COMMA); verifyCurrentToken(Token.RIGHT_PAREN); int[] values = new int[list.size()]; for (int i = 0; i  

Only this are suppose to fixed for it to work. The text file information is this

Scene.txt

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; IsoscelesTriangle Color (255, 0, 0) at (120, 120) Height 100 Width 200; Text Color(0, 0, 0) at (400, 200) "Hello World"; End.

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

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 Databases Questions!