I'm creating a method to be able to "print a histogram," and I'm trying to get it to reference the histogramData.length, to be able to loop and build each row, but it's not recognizing histogramData.length in the method.
I have the code in 2 separate files, one for main and one to build the methods.
Main looks like:
import becker.robots.*;
public class DrawHistogram extends Object
{ public static void main(String[] args)
{ City Edmonds = new City(12, 12);
HistogramRobot drawingBot = new HistogramRobot(Edmonds, 1, 1, Direction.EAST, 1000);
HistogramPrinter histPrinter = new HistogramPrinter();
int [] histogramData = new int[7];
histogramData[0] = 3; // The first element holds 3
histogramData[1] = 5; // The second element holds 5
histogramData[2] = 1; // The third element holds 1
histogramData[3] = 0; // The fourth element holds 0
histogramData[4] = 4; // The fifth element holds 4
histogramData[5] = 2; // The sixth element holds 2
histogramData[6] = 1; // The seventh element holds 1
drawingBot.drawRow();
}
}
And my method file looks like
import becker.robots.*;
class HistogramRobot extends Robot
{
HistogramRobot(City c, int st, int ave, Direction dir, int num)
{
super(c, st, ave, dir, num);
}
public void drawRow()
{
for(int counter = 0; counter < histogramData.length; counter++)
{
if( histogramData[counter] == 0)
{
this.turnRight();
this.move();
this.turnLeft();
}
for( int histoDrop = 0; histoDrop < histogramData[counter]; histoDrop++)
{
this.putThing();
this.move();
}
this.turnAround();
for (int moves = 0; moves < histogramData[counter]; moves++)
{
this.move();
}
this.turnLeft();
this.move();
this.turnLeft();
}
}
public void turnRight()
{
this.turnLeft();
this.turnLeft();
this.turnLeft();
}
public void turnAround()
{
this.turnLeft();
this.turnLeft();
}
}
And the error I'm getting for each mention of "histogramData" including "histogramData.length"
HistogramRobot.java:24: error: cannot find symbol
for( int histoDrop = 0; histoDrop < histogramData[counter]; histoDrop++)
^
symbol: variable histogramData
location: class HistogramRobot
What's causing the error and how can I fix it?
//I'm sorry! I could not get the spacing in the second part to work in my favor, let me know if you need clarification to answer.