Results 1 to 7 of 7
  1. #1
    coltragon is offline Senior Member
    Join Date
    Dec 2009
    Posts
    104
    Rep Power
    0

    Post Sun tutorials problems

    Hello java programmers :)

    I'm learning Java with the help of the tutorials on the Sun website(can't post link because this is my first post)
    Now i came at the part of classes, i was not expecting this to be hard. because it looked familar to other programming languages. But it was not that easy...

    I made a this:
    Java Code:
    class Bicycle {
    public static void main(String[] args) {
    
              Bicycle bike1 = new Bicycle();
              Bicycle bike2 = new Bicycle();
    
    
    bike1.changeCadence(30);
    bike1.changeGear(4);
    bike1.speedUp(5);
    bike1.speedUp(25);
    bike1.changeCoolness(100);
    bike1.printStates();
    
    bike2.changeCadence(25);
    bike2.speedUp(60);
    bike2.changeGear(6);
    bike2.coolnessUp(150);
    bike2.coolnessUp(250);
    bike2.printStates();
    }
    }
    when i was trying to compile it it gave me this error a lot of times:
    Java Code:
    Variable.java:8: cannot find symbol
    symbol:method changeCadence(int)
    location: class Bycicle 
    bike1.changeCadence(50); 
          ^
    so i googled this error but i didn't have much result.
    than i decided to replace it with the original code from the Sun website.
    but still it gave me the same error.
    do you know, what i can do?

    (sorry for my bad english, i'm just 14 years old and not a native english speaker)

    Regards,
    Coltragon
    Last edited by coltragon; 12-20-2009 at 03:50 PM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Your Bicycle class doesn't have any of the methods that it's trying to use. In fact it has no methods in it other than a single static main method.

  3. #3
    coltragon is offline Senior Member
    Join Date
    Dec 2009
    Posts
    104
    Rep Power
    0

    Default

    oh, first i need to declare the functions?
    if i remember correctly you do that like this.
    Java Code:
    int cadence=2;
    am i right?

  4. #4
    Char's Avatar
    Char is offline Member
    Join Date
    Dec 2009
    Posts
    41
    Rep Power
    0

    Default

    Quote Originally Posted by coltragon View Post
    oh, first i need to declare the functions?
    if i remember correctly you do that like this.
    Java Code:
    int cadence=2;
    am i right?
    no..this is how you put a value to a variable

    but are you sure this is whole code?
    i believe there should be atleast one more class

    or what should your code be doing?

  5. #5
    coltragon is offline Senior Member
    Join Date
    Dec 2009
    Posts
    104
    Rep Power
    0

    Default

    java.sun.com/docs/books/tutorial/java/concepts/class.htmlWhat Is a Class? (The Java™ Tutorials > Learning the Java Language > Object-Oriented Programming Concepts)[/url]
    there is the tutorial, i hope you can help me. but i did not understand evrything because it is written in hard to understand english

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Here is the link: What Is a Class? (The Java™ Tutorials > Learning the Java Language > Object-Oriented Programming Concepts)

    And here is the correct class:
    Java Code:
    class Bicycle {
    
           int cadence = 0;
           int speed = 0;
           int gear = 1;
    
           void changeCadence(int newValue) {
                cadence = newValue;
           }
    
           void changeGear(int newValue) {
                gear = newValue;
           }
    
           void speedUp(int increment) {
                speed = speed + increment;   
           }
    
           void applyBrakes(int decrement) {
                speed = speed - decrement;
           }
    
           void printStates() {
                System.out.println("cadence:"+cadence+" speed:"+speed+" gear:"+gear);
           }
    }
    You were confusing the Bicycle class above, with the BicycleDemo class below:
    Java Code:
    class BicycleDemo {
         public static void main(String[] args) {
    
              // Create two different Bicycle objects
              Bicycle bike1 = new Bicycle();
              Bicycle bike2 = new Bicycle();
    
              // Invoke methods on those objects
              bike1.changeCadence(50);
              bike1.speedUp(10);
              bike1.changeGear(2);
              bike1.printStates();
    
              bike2.changeCadence(50);
              bike2.speedUp(10);
              bike2.changeGear(2);
              bike2.changeCadence(40);
              bike2.speedUp(10);
              bike2.changeGear(3);
              bike2.printStates();
         }
    }
    One thing you'll learn if you stick with programming is that it is not very forgiving. Precision is paramount.

    Much luck and have fun!

  7. #7
    coltragon is offline Senior Member
    Join Date
    Dec 2009
    Posts
    104
    Rep Power
    0

Similar Threads

  1. XML+Java tutorials?
    By MK12 in forum XML
    Replies: 4
    Last Post: 03-19-2011, 01:47 AM
  2. Chat tutorials
    By imperium2335 in forum Java Applets
    Replies: 1
    Last Post: 06-29-2009, 04:39 AM
  3. Bluetooth Tutorials
    By medhat_fci in forum CLDC and MIDP
    Replies: 1
    Last Post: 08-11-2008, 03:15 AM
  4. My tutorials
    By gibsonrocker800 in forum Forum Lobby
    Replies: 2
    Last Post: 01-06-2008, 07:48 AM
  5. Tutorials for java, Help
    By cachi in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 06:09 AM

Posting Permissions

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