javadrjava

Undefined for a type (of turtle)


Hi Im doing an assignment for my class but got some trouble from the last part. This part I was making code to draw some phases and put in a world with a pic background and some customed features. The phases' code is the problem I believe. Can you guys check and help me with it?

import java.awt.Color;

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

    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);
    pic.show();
    Turtle tim = new Turtle(424,906,pic);
    tim.setPenColor(Color.red);
    tim.setPenWidth(6);
    tim.penDown();
    tim.moveTo(440,1046);
    tim.moveTo(522,1133);
    tim.moveTo(597,1133);
    tim.moveTo(671,1063);
    tim.moveTo(688,1009);
    tim.moveTo(698,882);
    tim.moveTo(657,790);
    tim.moveTo(495,771);
    tim.moveTo(424,906);

// draw the features
    tim.moveTo(450, 910);
    tim.drawEyeglasses(450, 910, 5, Color.white);
    tim.moveTo(505, 1020);
    tim.drawMustache(505,1020, 2, Color.black);


//Create Phase 1
    tim.moveTo(400,1300);
    tim.turnLeft();
    tim.drawPhase1();


//Create Phase 2
    tim.moveTo(300,1450);
    tim.drawPhase2();

  }
      public static void drawPhase1()
    {
      TurtleAlphabet.drawABoldSize(tim, Color.blue, true, 1);
      TurtleAlphabet.drawWBoldSize(tim, Color.white, true, 1);
      TurtleAlphabet.drawKBoldSize(tim, Color.red, true, 1);
      TurtleAlphabet.drawWBoldSize(tim, Color.blue, true, 1);
      TurtleAlphabet.drawABoldSize(tim, Color.white, true, 1);
      TurtleAlphabet.drawRBoldSize(tim, Color.red, true, 1);
      TurtleAlphabet.drawDBoldSize(tim, Color.blue, true, 1);
    }


    public static void drawPhase2()
    {
      TurtleAlphabet.drawABoldSize(tim, Color.yellow, true, 1);
      TurtleAlphabet.drawWBoldSize(tim, Color.orange, true, 1);
      TurtleAlphabet.drawABoldSize(tim, Color.yellow, true, 1);
      TurtleAlphabet.drawRBoldSize(tim, Color.orange, true, 1);
      TurtleAlphabet.drawDBoldSize(tim, Color.yellow, true, 1);
    }
}

and here's the system's responds:

File: C:\Users\nhock\Desktop\School Work\UNCC Fall 2018\1212\ITIS_1212\bookClasses\FaceCaptions.java  [line: 45]
Error: The method drawPhase1() is undefined for the type Turtle
File: C:\Users\nhock\Desktop\School Work\UNCC Fall 2018\1212\ITIS_1212\bookClasses\FaceCaptions.java  [line: 50]
Error: The method drawPhase2() is undefined for the type Turtle
File: C:\Users\nhock\Desktop\School Work\UNCC Fall 2018\1212\ITIS_1212\bookClasses\FaceCaptions.java  [line: 55]
Error: Turtle cannot be resolved to a variable
File: C:\Users\nhock\Desktop\School Work\UNCC Fall 2018\1212\ITIS_1212\bookClasses\FaceCaptions.java  [line: 56]
Error: tim cannot be resolved to a variable
File: C:\Users\nhock\Desktop\School Work\UNCC Fall 2018\1212\ITIS_1212\bookClasses\FaceCaptions.java  [line: 57]
Error: tim cannot be resolved to a variable
etc..

Solution

  • tim.drawPhase1() and tim.drawPhase2() calls the methods in the Turtle class or the intertited methods, seems like these methods are defined over the class Turtle, Modify the code to use the drawPhase1,2 methods statically and pass the Turtle instance

    FaceCaptions.drawPhase1(tim);
    
    FaceCaptions.drawPhase2(tim);
    
    
    public static void drawPhase1(Turtle tim){
        TurtleAlphabet.drawABoldSize(tim, Color.blue, true, 1);
        TurtleAlphabet.drawWBoldSize(tim, Color.white, true, 1);
        TurtleAlphabet.drawKBoldSize(tim, Color.red, true, 1);
        TurtleAlphabet.drawWBoldSize(tim, Color.blue, true, 1);
        TurtleAlphabet.drawABoldSize(tim, Color.white, true, 1);
        TurtleAlphabet.drawRBoldSize(tim, Color.red, true, 1);
        TurtleAlphabet.drawDBoldSize(tim, Color.blue, true, 1);
    }
    
    public static void drawPhase2(Turtle tim){
        TurtleAlphabet.drawABoldSize(tim, Color.yellow, true, 1);
        TurtleAlphabet.drawWBoldSize(tim, Color.orange, true, 1);
        TurtleAlphabet.drawABoldSize(tim, Color.yellow, true, 1);
        TurtleAlphabet.drawRBoldSize(tim, Color.orange, true, 1);
        TurtleAlphabet.drawDBoldSize(tim, Color.yellow, true, 1);
    }