Results 1 to 6 of 6
  1. #1
    nfalato is offline Member
    Join Date
    Jan 2017
    Posts
    5
    Rep Power
    0

    Default Turtle Java Program

    So I am working on a program where I have this little turtle that is going to draw out my name or a polygon or a colored radial wheel where depending on what angle the turtle is facing the color is different.
    I am not very good with the Java language and was wondering on how to approach this program.
    Here is what I have so far, where there is the EndWorld w = new EndWorld(); and AnimatedTurtle t = new AnimatedTurtle(w); I was given this code to use by my professor in order to see what action the turtle does
    Java Code:
                public class HelloTurtles {
               
                public static void drawName (Turtle t){
                 //I have tried to use t.forward (); t.turnRight(); but I am not sure how these work
                }
            
                public static void radial (Turtle t, int numLines, int lineLength){
                 //this is where that colored radial wheel comes into play but I have no idea how to start it.
                }
    
                public static void manyPolygons (Turtle t, int numPolys, int numSides, int sideLen){
                 //here is where the turtle will draw out whatever type of polygon I set it to draw but multiple times , like if 
                 // I were to have it draw a circle, it would draw it in spirals until it's come to a stop 
                 }
    
                public static void drawPolygon (Turtle t, int numSides, int sideLen){
                for (numSides = 0; numSides < 4; numSides ++);
                {
                  sideLen = 10;
                  t.forward (pixels: 100);
                  t.turn      (degress: 90);
                  t.forward (pixels: 100);
                  t.turn       (degrees: 90);
                 }
               //I dont know if i coded this right .. i can't figure out how to call this into the main method to check...
                }
    
                public static void main (String [] args){
                 
                 EndWorld w = new EndWorld();
                 AnimatedTurtle t = new AnimatedTurtle(w);
     
                 HelloTurtles.menu(); // this calls the menu method into the main method, but i'm stuck on how to get the right method called into the         main  depending on what choice the user makes in the menu to begin with...
                }
    
                public static String menu(){
                JPanel = panel = new JPanel();
                panel.add(new JRadioButton (text: "radio"));
                String values [] = {"Name", "Polygon", "Many Polygons", "Radial");
                Object choice = JOptionPane.showInputDialog (parentComponent: null,
                                        message: "Choose the demo to show", titel: "Choose Demo",
                                        JOptionPane.DEFAULT_OPTION, icon: null, values, initialSelectionValue: "0");
                 if(choice == null){
                  System.exit (status: 0);
                  }
                  return choice.toString();
                } 
      }
    Last edited by nfalato; 02-16-2017 at 09:21 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    19,904
    Rep Power
    30

    Default Re: Turtle Java Program

    There a several third party classes used in the code. Does the author of those classes support them?
    Is there a website for them?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    nfalato is offline Member
    Join Date
    Jan 2017
    Posts
    5
    Rep Power
    0

    Default Re: Turtle Java Program

    Yes the author supports them and no there wasn't a website for it. They were already made when I unzipped the file and opened it in IntelliJ

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    19,904
    Rep Power
    30

    Default Re: Turtle Java Program

    the author supports them
    That's good. Then you should be able to ask him about any problems you are having with the classes.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    381
    Rep Power
    4

    Default Re: Turtle Java Program

    Right now you are stuck in the main() method. You have called the menu() method that returns a user choice in form of a String, but you never use that String. What is the idea here, do you want to call a method based on the user choice? And then the chosen method makes the turtle move?
    As Norm said, the turtle movement will remain your secret if you don't show the class.

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,145
    Rep Power
    12

    Default Re: Turtle Java Program

    Ok, I guess I will comment on the fact that his original post has some strange syntax in some method calls. Not certain what the identifiers are as they are not defined (e.g. pixels). But the : should be a , (unless you are using some type of pre-processor).

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Epitrochoid using Turtle Graphics?
    By darkzboy in forum New To Java
    Replies: 1
    Last Post: 10-27-2013, 11:38 PM
  2. turtle graphics
    By Kareem Mesbah in forum New To Java
    Replies: 1
    Last Post: 10-20-2012, 09:15 PM
  3. Downloading Turtle Graphics and Other Packages
    By Godsarmy4vr2 in forum New To Java
    Replies: 4
    Last Post: 02-28-2010, 07:19 PM
  4. Turtle assignment
    By jmc724 in forum New To Java
    Replies: 11
    Last Post: 07-16-2008, 10:11 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •