gpt4 book ai didi

java - 未定义(海龟)类型

转载 作者:太空宇宙 更新时间:2023-11-04 10:05:26 32 4
gpt4 key购买 nike

嗨,我正在为类(class)做作业,但最后一部分遇到了一些麻烦。这部分我正在编写代码来绘制一些阶段,并放入一个具有图片背景和一些自定义功能的世界中。我认为阶段的代码是问题所在。你们能帮我检查一下吗?

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);
}
}

这是系统的响应:

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..

最佳答案

tim.drawPhase1()tim.drawPhase2()调用Turtle类中的方法或中间的方法,看起来这些方法是在Turtle类上定义的,修改代码以静态使用drawPhase1,2方法并传递Turtle实例

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);
}

关于java - 未定义(海龟)类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53000114/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com