Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m getting syntax errors on two lines below and can\'t figure them out. This i

ID: 3594063 • Letter: I

Question

I'm getting syntax errors on two lines below and can't figure them out. This is code that was an answer to a previous question I had. I've prefixed the lines in question with ****errors so that it would be easy to see.

import javafx.scene.canvas.Canvas;

import javafx.scene.canvas.GraphicsContext;

import javafx.scene.paint.Paint;

/**

* GraphPanelFX creates the Canvas and draws the graph

  

*

*/

public class GraphPanelFX {

   double gridWidth;

   double gridHeight;

   double xLeft, xRight, yTop, yBottom;

   GraphManager graphMgr;

   Canvas graphCanvas;

   GraphicsContext gc;

   GraphPanelFX(GraphManager graphManager, double CANVAS_WIDTH, double CANVAS_HEIGHT) {

       graphMgr = graphManager;

       graphCanvas = new Canvas(CANVAS_WIDTH, CANVAS_HEIGHT);

       gc = graphCanvas.getGraphicsContext2D();

   }

   public Canvas getGraphCanvas(GraphPanelFX graphPanel2) {

       return graphCanvas;

   }

   /**

   * drawGraph is called when the "Graph a Function" button is selected

   */

   public void drawGraph() {

       gridWidth = gc.getCanvas().getWidth();

       gridHeight = gc.getCanvas().getHeight();

       gc.clearRect(0,0,gridWidth,gridHeight);

       System.out.println("in paintComponent(); width="+gridWidth+"; height="+gridHeight);

       drawGraph(gridWidth, gridHeight-10, gc);

   }

   /**

   * Draws line segments from left extent to right extent, pixel by pixel, transforming points

   * to the coordinate system of the panel.

   * @param gridWidth2 the width of the panel in pixels

   * @param gridHeight the height of the panel in pixels

   * @param g2 the Graphics2D instance generated by Java library classes and sent as a argument of paintComponent

   */

   public void drawGraph(double gridWidth2, double gridHeight, GraphicsContext gc) {

       double x0=xLeft, y0, x1=0;

       double x1Draw, x0Draw, y1Draw, y0Draw;

       int functionChoice = graphMgr.getFunctionChoice();

       Function fn = graphMgr.getFunction(functionChoice);

       //check to make sure a function choice has been made before drawing

       if(functionChoice>0) {

           xLeft = graphMgr.getLeftExtent();

           xRight = graphMgr.getRightExtent();

           graphMgr.setExtents(xLeft, xRight, gridWidth2);

           yTop = graphMgr.getTopExtent();

           yBottom = graphMgr.getBottomExtent();

           //draw a gray horizontal line at y=0

                   gc.setStroke(Paint.valueOf("Gray"));

           y1Draw = fn.originToPlot(gridHeight, yBottom, yTop);

           gc.strokeLine(0,y1Draw,gridWidth2,y1Draw);

           //set the graphing color and width

           gc.setStroke(Paint.valueOf("BLUE"));

           gc.setLineWidth(2);

           x0=xLeft;

           y0 = graphMgr.getFnValue(functionChoice, x0);

           //loop pixel by pixel, drawing the function between each value of x

**** errors on the for loop

           for (int i=1; i<gridwidth2; i++)="" {="" x1="x0+((xRight-xLeft)/gridWidth2);" x0draw="i;" x1draw="i+1;" y1draw="fn.fnValueToPlot(x1," gridheight,="" ybottom,="" ytop);="" y0draw="fn.fnValueToPlot(x0," system.out.println("x0="+x0+" y0="+graphMgr.getFnValue(functionChoice, x0)+" ;="" xleft="+xLeft+" xright="+xRight+" maxy="+yTop+" miny="+yBottom+" gridwidth="+d);

           }

           /**

           * Gets the left extent of the function to be considered

           * @return the x value of the left extent as a double

           */

           public double getLeftExtent () {

               return xLeft;

           }

           /**

           * Gets the right extent of the function to be considered

           * @return the x value of the right extent as a double

           */

           public double getRightExtent () {

               return xRight;

           }

           /**

           * Gets the top extent of the function to be considered

           * @return the maximum f(x) value that occurs from left to right

           */

           public double getTopExtent () {

               return yTop;

           }

           /**

           * Gets the bottom extent of the function to be considered

           * @return the minimum f(x) value that occurs from left to right

           */

           public double getBottomExtent () {

               return yBottom;

           }

           /**

           * Overrides toString, creating a string describing the functions' formulas

           */

           public String toString() {

*****errors on the String below...

               String rtnString = " ";="" rtnstring+="1. " +function1.tostring()+" ";="" +function2.tostring()+" ";="" +function3.tostring()+" ";="" return="" rtnstring;="" }=""

Explanation / Answer

Fixed the issues with errors in program...

Issues found are: "Unnecessary quotes and using wrong variable names".

Modified code

import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Paint;

/**
* GraphPanelFX creates the Canvas and draws the graph
*
*
*/
public class GraphPanelFX {

double gridWidth;
double gridHeight;
double xLeft, xRight, yTop, yBottom;
GraphManager graphMgr;
Canvas graphCanvas;
GraphicsContext gc;

GraphPanelFX(GraphManager graphManager, double CANVAS_WIDTH, double CANVAS_HEIGHT) {
graphMgr = graphManager;
graphCanvas = new Canvas(CANVAS_WIDTH, CANVAS_HEIGHT);
gc = graphCanvas.getGraphicsContext2D();
}

public Canvas getGraphCanvas(GraphPanelFX graphPanel2) {
return graphCanvas;
}

/**
* drawGraph is called when the "Graph a Function" button is selected
*/
public void drawGraph() {
gridWidth = gc.getCanvas().getWidth();
gridHeight = gc.getCanvas().getHeight();
gc.clearRect(0, 0, gridWidth, gridHeight);
System.out.println("in paintComponent(); width=" + gridWidth + "; height=" + gridHeight);

drawGraph(gridWidth, gridHeight - 10, gc);
}

/**
* Draws line segments from left extent to right extent, pixel by pixel,
* transforming points to the coordinate system of the panel.
*
* @param gridWidth2 the width of the panel in pixels
* @param gridHeight the height of the panel in pixels
* @param g2 the Graphics2D instance generated by Java library classes and
* sent as a argument of paintComponent
*/
public void drawGraph(double gridWidth2, double gridHeight, GraphicsContext gc) {
double x0 = xLeft, y0, x1 = 0;
double x1Draw, x0Draw, y1Draw, y0Draw;
int functionChoice = graphMgr.getFunctionChoice();
Function fn = graphMgr.getFunction(functionChoice);

//check to make sure a function choice has been made before drawing
if (functionChoice > 0) {

xLeft = graphMgr.getLeftExtent();
xRight = graphMgr.getRightExtent();

graphMgr.setExtents(xLeft, xRight, gridWidth2);

yTop = graphMgr.getTopExtent();
yBottom = graphMgr.getBottomExtent();

//draw a gray horizontal line at y=0
gc.setStroke(Paint.valueOf("Gray"));
y1Draw = fn.originToPlot(gridHeight, yBottom, yTop);
gc.strokeLine(0, y1Draw, gridWidth2, y1Draw);

//set the graphing color and width
gc.setStroke(Paint.valueOf("BLUE"));
gc.setLineWidth(2);
x0 = xLeft;
y0 = graphMgr.getFnValue(functionChoice, x0);
//loop pixel by pixel, drawing the function between each value of x
for (int i = 1; i < gridWidth2; i++) {
x1 = x0 + ((xRight - xLeft) / gridWidth2);
x0Draw = i;
x1Draw = i + 1;
y1Draw = fn.fnValueToPlot(x1, gridHeight, yBottom, yTop);
y0Draw = fn.fnValueToPlot(x0, gridWidth, yBottom, yTop);
System.out.println("x0=" + x0 + " y0=" + graphMgr.getFnValue(functionChoice, x0) + " xleft=" + xLeft + " xright=" + xRight + " maxy=" + yTop + " miny=" + yBottom);
}

/**
* Gets the left extent of the function to be considered
*
* @return the x value of the left extent as a double
*/
}
}

public double getLeftExtent() {
return xLeft;
}

/**
* Gets the right extent of the function to be considered
*
* @return the x value of the right extent as a double
*/
public double getRightExtent() {
return xRight;
}

/**
* Gets the top extent of the function to be considered
*
* @return the maximum f(x) value that occurs from left to right
*/
public double getTopExtent() {
return yTop;
}

/**
* Gets the bottom extent of the function to be considered
*
* @return the minimum f(x) value that occurs from left to right
*/
public double getBottomExtent() {
return yBottom;
}

/**
* Overrides toString, creating a string describing the functions' formulas
*/
public String toString() {
String rtnString = " ";
rtnString += "1. " + function1.tostring() + " ";
rtnString += function2.tostring() + " ";
rtnString += function3.tostring() + " ";
return rtnString;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote