Проект «Ява-черепаха» - похоже, я не могу отладить свои ошибки - PullRequest
0 голосов
/ 11 декабря 2018

Я пытаюсь завершить проект Turtle в Dr. Java, в котором есть несколько комнат с вопросами для продвижения, и я не могу найти и исправить ошибки, которые я получаю.

Вот мой код:

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

Я пытался получить помощь от нескольких людей и, похоже, не могу ее исправить.

1 Ответ

0 голосов
/ 11 декабря 2018

Ваши ошибки, как представляется, состоят из опечаток:

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 строк кода принадлежат методу, который так и не был объявлен!

У меня нет «черепашки доктора Ява» для сравнения, но ниже я переделываю ваш код, исправляющий столько проблем, сколько ясмог обнаружить:

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