So I have a program that I'm trying to run which plots a line, square, that takes in the command line arguments say l 5 s 4 c 6. With this I plot out the shapes using a 2Darray
. In my program I have a driver class, a char2D
class(my class that handles the 2darray
), and myLine
. myLine
derives from char2D
using inheritance.
My question is this: Why do I get a compiling error cannot be referenced from static context? Would I have to move the switch statement that parses the command line arguments to a different method? If so would I have to do anything other than just cut the statement into a new method?
Here's my compiling error.
/home/miguel/School/project3 v2/driver.java:11: error: non-static method myLine(int) cannot be referenced from a static context myLine( size1 ); ^
Here's my driver class (Ignore the commented out sections as I have to fix these since I rewrote my program):
public class driver {
public static void main(String[] args ){
String type = args[0];
int size;
switch (type.toLowerCase().charAt( 0 )) {
case 'l':
int size1;
size1 = Integer.parseInt( args[1] );
myLine( size1 );
break;
// case 's' :
// size2 = Integer.parseInt(args[1]);
// mySquare( size );
// break;
// case 'c' :
// size3 = Integer.parseInt(args[1]);
// myCube( size );
// break;
}
}
}
}
public static void myLine( int size ){
myLine( size );
}
// System.out.print( "*"); // don't need to print in here
//myLine(int size);
// public int mySquare( int size ) {
//for (i = 0; i < size ; i++)
// mySquare( size );
}
// public void myCube( int size ){ // z will be x but only have the length of it
//z = size + .5
// myCube(size )
// }
Here's my char2D class
public class char2D {
protected int width; protected int height; protected char char2D[][];
public char2D( int width, int height ){ //line
this.width = width;
this.height = height;
char2D = new array[height][width];
}
public void grow( int width, int height ){ //note width and height are changing in this method
this.height += height;
this.width += width;
char2D = new array[this.height][this.width];
}
public void plot( int x1, int y1 ){
char2D[y1][x1] = '*';
}
public static toString( char2D )
return char2D.toString();
}
Here's my myLine class:
public class myLine extends char2D{
private int size1;
public myLine(int size1){
super( size1, 1 );
this.size1 = size1;
plotLine();
}
private void plotLine(){
for( int i = 0; i < size1 ; i++){
plot( 0 , i );
}
}
}