简体   繁体   中英

Dr. Java compiles my program with no errors/issues but isn't running the code to completion

I'm in my first semester at university and am working on a small assignment using the educational simpleturtle/turtle class(es).

I'm writing my programs using Dr. Java (IDE), and when I go to run my program, it compiles completely fine, but when I run the program it jumps out of execution at random points each time I run it. It's never consistent on when it jumps out, but only does it when I run this program that I've been working on.

All my other programs work fine, when I go back to run them. It's just this one. I've uninstalled and reinstalled jdk and dr. java, I've restarted my computer, reset to the defaults on dr. java, and re-mapped my extra classes path link to my educational course files and no dice. Any ideas?

import java.util.*;
import java.awt.*;

/**
 * Class that represents a turtle which is similar to a Logo turtle.
 * This class inherts from SimpleTurtle and is for students
 * to add methods to.
 *
 * Copyright Georgia Institute of Technology 2004
 * @author Barb Ericson ericson@cc.gatech.edu
 */
public class Turtle extends SimpleTurtle
{
  ////////////////// constructors ///////////////////////

  /** Constructor that takes the x and y and a picture to
   * draw on
   * @param x the starting x position
   * @param y the starting y position
   * @param picture the picture to draw on
   */
  public Turtle (int x, int y, Picture picture) 
  {
    // let the parent constructor handle it
    super(x,y,picture);
  }

  /** Constructor that takes the x and y and a model
   * display to draw it on
   * @param x the starting x position
   * @param y the starting y position
   * @param modelDisplayer the thing that displays the model
   */
  public Turtle (int x, int y, 
                 ModelDisplay modelDisplayer) 
  {
    // let the parent constructor handle it
    super(x,y,modelDisplayer);
  }

  /** Constructor that takes the model display
   * @param modelDisplay the thing that displays the model
   */
  public Turtle (ModelDisplay modelDisplay) 
  {
    // let the parent constructor handle it
    super(modelDisplay);
  }

  /**
   * Constructor that takes a picture to draw on
   * @param p the picture to draw on
   */
  public Turtle (Picture p)
  {
    // let the parent constructor handle it
    super(p);
  }  

  /////////////////// methods ///////////////////////


  public static void main(String[] args)
  {
    World earth = new World();
    Turtle t1 = new Turtle(earth);
    t1.forward();
  }

  public void drawT() { 
    this.forward(100); 
    this.turnLeft(); 
    this.penUp(); 
    this.forward(40); 
    this.turn(180); 
    this.penDown(); 
    this.forward(80); 
    this.hide();

  }
  public void drawSquare()
  {
    this.turnRight();
    this.forward(30);
    this.turnRight();
    this.forward(30);
    this.turnRight();
    this.forward(30);
    this.turnRight();
    this.forward(30);
  }

  public void drawSquare2()
  {
    int width = 30;
    this.turnRight();
    this.forward(width);
    this.turnRight();
    this.forward(width);
    this.turnRight();
    this.forward(width);
    this.turnRight();
    this.forward(width);
  }

  /**
   * Method to draq a square with a width and height
   * of some passed amount.
   * @param width the width and height to use
   */
  public void drawSquare(int width)
  {
    this.turnRight();
    this.forward(width);
    this.turnRight();
    this.forward(width);
    this.turnRight();
    this.forward(width);
    this.turnRight();
    this.forward(width);
  }

 public void drawHorns(int x, int y, Color c){

   //written for large foreground element

   //set pen up til you move turtle to location to draw mustache
   this.penUp();

   //move to coordinates to draw eyeglasses
   this.moveTo(x, y);

   //set pen color
   this.setPenColor(c);

   //set pen width
   this.setPenWidth(4);
   //move left
   this.turnLeft();
   this.forward(20);

   //set pen down
   this.penDown();
   //turn up
   this.turnRight();
   //draw left horn - angled out
   this.turn(-65);
   this.forward(20);
   this.turn(30);
   this.forward(20);
   this.turn(30);
   this.forward(20);
   this.turn(30);
   this.forward(20);
   this.turn(30);
   this.forward(5);
   this.turn(125);
   this.forward(20);
   this.turn(-30);
   this.forward(10);
   this.turn(-30);
   this.forward(34);
   this.turn(90);
   this.forward(25);

   //move away to draw the other set of horns
   this.turn(-110);
   //put a pen up here
   this.penUp();
   this.forward(130);
   //put a pen down here
   this.penDown();

   //draw right side of the horns
   this.turn(-125);
   this.forward(25);
   this.turnRight();
   this.forward(20);
   this.turn(-30);
   this.forward(20);
   this.turn(-30);
   this.forward(20);
   this.turn(-30);
   this.turnRight();
   this.turn(90);
   this.forward(20);
   this.turn(30);
   this.forward(20);
   this.turn(30);
   this.forward(20);
   this.turn(20);
   this.forward(20);

   //pen up
   this.penUp();
 }

 public void drawCensor(int x, int y, Color c){

   //pen up
   this.penUp();

   //move to location
   this.moveTo(x,y);

   //set pen color
   this.setPenColor(c);

   //set pen width
   this.setPenWidth(20);

   //pendown
   this.penDown();

   //draw censor bar
   this.turnRight();
   this.forward(5);
   this.turn(180);
   this.forward(10);

   //penUp
   this.penUp();
 }

 public void drawEyeglasses(int x, int y, Color c){

   //pen up
   this.penUp();
  //move to location
   this.moveTo(x,y);
   //set pen color
   this.setPenColor(c);
   this.setPenWidth(2);

   //pen down
   this.penDown();

   //draw middle stem
   this.turnLeft();
   this.forward(3);
   this.turn(180);
   this.forward(6);

   //draw right eyeglass piece
   this.turnLeft();
   this.forward(3);
   this.turn(45);
   this.forward(6);
   this.turn(45);
   this.forward(6);
   this.turn(45);
   this.forward(6);
   this.turn(45);
   this.forward(6);
   this.turn(45);
   this.forward(6);
   this.turn(45);
   this.forward(6);
   this.turn(45);
   this.forward(6);
   this.turn(45);
   this.forward(3);

   //move to left side
   this.turnLeft();
   this.forward(6);
   this.turnRight();
   this.forward(3);
   this.turn(-45);
   this.forward(6);
   this.turn(-45);
   this.forward(6);
   this.turn(-45);
   this.forward(6);
   this.turn(-45);
   this.forward(6);
   this.turn(-45);
   this.forward(6);
   this.turn(-45);
   this.forward(6);
   this.turn(-45);
   this.forward(6);
   this.turn(-45);
   this.forward(3);

   //penup
   this.penUp();
   this.setHeading(90);
 }
}
// this } is the end of class Turtle, put all new methods before this
// Face Features Program

import java.awt.Color;

public class FaceFeatures 
{
  public static void main(String [] args) 
  {

    //Choose Background Image for Program 
    String filename;

    if (args.length > 0) {
       // got a filename passed into program as a runtime parameter
       filename = args[0];      
       System.out.println("Filename passed in: " + filename);

    } else {
       // ask user for a picture
       filename = FileChooser.pickAFile();
       System.out.println("User picked file: " + filename);
    }

    // use the filename to create the picture object
    Picture pic = new Picture(filename);

    // create turtle
    Turtle daniel = new Turtle(pic);

    //show pic for writing program
    pic.show();

    //set pen up
    daniel.penUp();

    //set pen color and thickness
    daniel.setPenColor(Color.red);
    daniel.setPenWidth(5);

    //move to starting coordinate
    daniel.moveTo(173,162);

    //set pen down
    daniel.penDown();

    //outline face
    daniel.moveTo(173, 162);
    daniel.moveTo(165, 170);
    daniel.moveTo(165, 184);
    daniel.moveTo(146, 192);
    daniel.moveTo(141, 205);
    daniel.moveTo(132, 213);
    daniel.moveTo(126, 235);
    daniel.moveTo(117, 259);
    daniel.moveTo(114, 286);
    daniel.moveTo(114, 311);
    daniel.moveTo(121, 339);
    daniel.moveTo(128, 359);
    daniel.moveTo(141, 375);
    daniel.moveTo(161, 385);
    daniel.moveTo(176, 383);
    daniel.moveTo(189, 376);
    daniel.moveTo(210, 349);
    daniel.moveTo(242, 321);
    daniel.moveTo(255, 304);
    daniel.moveTo(266, 287);
    daniel.moveTo(272, 276);
    daniel.moveTo(282, 263);
    daniel.moveTo(289, 252);
    daniel.moveTo(293, 226);
    daniel.moveTo(289, 213);
    daniel.moveTo(266, 217);
    daniel.moveTo(258, 212);
    daniel.moveTo(259, 205);
    daniel.moveTo(238, 208);
    daniel.moveTo(219, 200);
    daniel.moveTo(193, 185);
    daniel.moveTo(190, 183);
    daniel.moveTo(177, 167);
    daniel.moveTo(173, 162);



    //Draw Horns Method
    daniel.drawHorns(195, 110, Color.red);

    //setheading
    daniel.setHeading(0);

    //sensor over the male homonid
    daniel.drawCensor(398, 395, Color.black);
    //setheading
    daniel.setHeading(0);

    //sensor over the female homonid

    //setheading
    daniel.setHeading(0);
    daniel.drawCensor(472, 309, Color.black);

    //setheading
    daniel.setHeading(0);
    daniel.drawCensor(537, 317, Color.black);

    //set heading
    daniel.setHeading(0);

    //draw eyeGlasses method ( on male homonid )
    daniel.drawEyeglasses(388, 182, Color.green);

    //set heading
    daniel.setHeading(0);

    //draw eyeGlassesmethod ( on female homonid )
    daniel.drawEyeglasses(531, 228, Color.magenta);
 }
}

Try Editing your constructor. Or, perhaps theres a misplaced end curly bracket

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM