TurtleGraphics DrawLine Problem in program SmilingFace.java
Hi,
I am helping to tutor some students with java using the textbook "Java
Basics" by Lambert and Osborne. One program calls for the use of
TurtleGraphics. The students are able to get the drawcircle part to
work, but do not get the DrawLine portion to perform. The program
called, SmilingFace, calls for a circle to get created (as a smiley
face), with two small circles for eyes, and three line segments to make
up the smile. It uses a helper m
When run, the result is the "head" with the two "eyes", but the smile
does not get drawn.
Does anyone know what might be causing the problem?
Here is the code for the two classes, TestSmilingFace and SmilingFace.
SmilingFace.java:
import TurtleGraphics.*;
import java.awt.Color;
public class SmilingFace {
private StandardPen pen;
private double xPosition, yPosition;
public SmilingFace(){
xPosition = 0;
yPosition = 0;
pen = new StandardPen();
pen.setColor(Color.yellow);
}
public SmilingFace (double x, double y) {
this();
xPosition = x;
yPosition = y;
}
public void draw(){
double radius = 25.0;
drawCircle(xPosition, yPosition, radius);
drawCircle(xPosition - radius / 2.5, yPosition + radius / 3, radius
/ 4);
drawCircle(xPosition + radius / 2.5, yPosition + radius / 3, radius
/ 4);
drawLine(xPosition - radius / 3, yPosition - radius / 2, xPosition +
radius / 3, yPosition - radius / 2);
drawLine(xPosition - radius / 3, yPosition - radius / 2, xPosition +
radius / 3 - 5, yPosition - radius / 2 + 5);
drawLine(xPosition + radius / 3, yPosition - radius / 2, xPosition +
radius / 3 + 5, yPosition - radius / 2 + 5);
}
public void erase(){
pen.setColor(Color.white);
draw();
pen.setColor(Color.yellow);
}
public void move(double x, double y) {
xPosition = x;
yPosition = y;
}
private void drawCircle (double x, double y, double r) {
double side = 2.0 * Math.PI * r / 120;
pen.up();
pen.move(x + r, y - side / 2.0);
pen.setDirection(90);
pen.down();
for (int i = 0; i < 120; i++) {
pen.move(side);
pen.turn(3);
}
}
private void drawLine(double x1, double y1, double x2, double y2) {
}
}
TestSmilingFace.java:
import TurtleGraphics.*;
import TerminalIO.*;
public class TestSmilingFace {
public static void main(String [] args){
KeyboardReader reader = new KeyboardReader();
double x, y, radius;
x = reader.readDouble("Initial x position: ");
y = reader.readDouble("Initial y position: ");
SmilingFace face = new SmilingFace(x, y);
face.draw();
while (true) {
x = reader.readDouble("New x position: ");
y = reader.readDouble("New y position: ");
face.erase();
face.move(x, y);
face.draw();
}
}
}