我正在尝试用Java博士完成一个Turtle项目,该项目有多个房间有待解决,我似乎找不到并解决我遇到的错误。
这是我的代码:
0
import java.awt.*;
public class TurtleDrawing
{
public static void main(String args[])
{
boolean one = roomOne();
}
public static boolean roomOne();
{
World wor = new World(500,500);
Turtle turOne = new Turtle(0,0, wor);
Picture picOne = new Picture("grocery.jpg");
Picture pitTwo = new Picture("anteater.webp");
turOne.penUp();
turone.moveTo(200,200);
turOne.drop(picOne);
turOne.moveTo(300,100);
turOne.drop(picTwo);
turOne.hide();
turOne.forward(1);
JOptionPane.showMessageDialog(null, "Dequavis the anteater is shopping for
bananas at his local grocery store");
String str = JOptionPane.showImputDialog(null, "If each bundle costs 3
dollars and he buys 2 bundles how much will he pay?");
if (str.equals("6"))
return true;
else return false;
}
World wor = new World(1100,800);
Turtle turOne = new Turtle(wor);
turOne.penUp();
Picture picOne = new Picture ("space.jpg");
turOne.moveTo(0,0);
turOne.drop (picOne);
Turtle turTwo = new Turtle(wor);
turTwo.penUp();
Picture picTwo = new Picture ("rocket.png");
turTwo.moveTo(200,500);
turTwo.drop (picTwo);
turTwo.forward(1);
Turtle turThree = new Turtle(wor);
turThree.penUp();
Picture picThree = new Picture ("unircorn.png");
turTwo.moveTo(700,600);
turThree.drop (picThree);
turThree.forward(1);
Turtle turFour = new Turtle(wor);
turFour.penUp();
Picture picFour = new Picture ("spongebob.png");
turTwo.moveTo(400,600);
turFour.drop (picFour);
turFour.forward(1);
turOne.penUp();
double x = 0 ;
double y = 0;
int t = 0;
turOne.setColor(Color.BLUE);
while (t < 200)
{
if(t > 0)
turOne.penDown();
x = (16 * Math.sin(t)* Math.sin(t) * Math.sin(t))* -1 + 500 ;
y = (13 * Math.cos(t) - 5 * Math.cos (2 * t) - 2 * Math.cos(3 * t))-
Math.cos(4 * t) * -10 + 400;
t = t + 1;
turOne.moveTo((int)x, (int)y);
}
}
public static void heart( Turtle turOne , int startX, int startY)
{
double x = 0;
double y = 0;
int t = 0;
turOne.penUp();
if( t % 3 == 1)
turOne.setColor(Color.PINK);
if( t % 3 == 2)
}
}
我尝试从多个人那里获得帮助,但似乎无法解决。
答案 0 :(得分:1)
您的错误似乎由错别字组成:
showImputDialog -> showInputDialog
pitTwo -> picTwo
turone -> turOne
unircorn -> unicorn
复制和粘贴错误:
Turtle turFour = new Turtle(wor);
turFour.penUp();
Picture picFour = new Picture ("spongebob.png");
turTwo.moveTo(400,600); // probably should be turFour
turFour.drop (picFour);
turFour.forward(1);
以及不完整的代码片段:
if( t % 3 == 1)
turOne.setColor(Color.PINK);
if( t % 3 == 2)
最糟糕的是大约30行代码属于一个从未声明的方法!
我没有可比拟的Java乌龟博士,但下面是我对您的代码进行的修复,修复了我能检测到的许多问题:
import java.awt.*;
public class TurtleDrawing
{
public static void main(String args[])
{
boolean one = roomOne();
}
public static boolean roomOne()
{
World wor = new World(500, 500);
Picture picOne = new Picture("grocery.jpg");
Picture picTwo = new Picture("anteater.webp");
Turtle turOne = new Turtle(0, 0, wor);
turOne.penUp();
turOne.moveTo(200, 200);
turOne.drop(picOne);
turOne.moveTo(300, 100);
turOne.drop(picTwo);
turOne.hide();
turOne.forward(1);
JOptionPane.showMessageDialog(null, "Dequavis the anteater is shopping for bananas at his local grocery store");
String str = JOptionPane.showInputDialog(null, "If each bundle costs 3 dollars and he buys 2 bundles how much will he pay?");
return str.equals("6");
}
public static void unamed_function()
{
World wor = new World(1100, 800);
Picture picOne = new Picture("space.jpg");
Picture picTwo = new Picture("rocket.png");
Picture picThree = new Picture("unicorn.png");
Picture picFour = new Picture ("spongebob.png");
Turtle turOne = new Turtle(wor);
turOne.penUp();
turOne.moveTo(0, 0);
turOne.drop(picOne);
Turtle turTwo = new Turtle(wor);
turTwo.penUp();
turTwo.moveTo(200, 500);
turTwo.drop(picTwo);
turTwo.forward(1);
Turtle turThree = new Turtle(wor);
turThree.penUp();
turThree.moveTo(700, 600);
turThree.drop(picThree);
turThree.forward(1);
Turtle turFour = new Turtle(wor);
turFour.penUp();
turFour.moveTo(400, 600);
turFour.drop(picFour);
turFour.forward(1);
turOne.setColor(Color.BLUE);
int t = 0;
while (t < 200)
{
double x = (16 * Math.sin(t) * Math.sin(t) * Math.sin(t)) * -1 + 500;
double y = (13 * Math.cos(t) - 5 * Math.cos(2 * t) - 2 * Math.cos(3 * t)) - Math.cos(4 * t) * -10 + 400;
turOne.moveTo((int)x, (int)y);
t = t + 1;
turOne.penDown();
}
}
public static void heart(Turtle turOne, int startX, int startY)
{
double x = 0;
double y = 0;
int t = 0;
turOne.penUp();
if (t % 3 == 1)
{
turOne.setColor(Color.PINK);
}
else if (t % 3 == 2)
{
turOne.setColor(Color.GREEN);
}
}
}