public class Exercise extends Frame{
private final static int size = 250;
public static void main(String[] args){
Exercise ex = new Exercise();
}
public Exercise(){
setSize( size*2, size*2);
setTitle(getClass().getName());
setVisible( true );
}
public void paint(Graphics g){
boolean isFirst = true;
g.translate(size,size);
int range = size;
int step = 1;
int old = 0;
for(int x=-range;x<=range;x+=step){
int y = function(x++);
if(isFirst){
isFirst = false;
}else{
g.drawLine(x-1,old,x,y);
}
old = y;
}
}
public int function(double x){
double m = 2;
double b = 20;
double y = m*x+m;
return (int)y;
}
}