Results 1 to 7 of 7
Thread: Sun tutorials problems
- 12-20-2009, 03:36 PM #1
Senior Member
- Join Date
- Dec 2009
- Posts
- 104
- Rep Power
- 0
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:
when i was trying to compile it it gave me this error a lot of times: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(); } }
so i googled this error but i didn't have much result.Java Code:Variable.java:8: cannot find symbol symbol:method changeCadence(int) location: class Bycicle bike1.changeCadence(50); ^
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,
ColtragonLast edited by coltragon; 12-20-2009 at 03:50 PM.
-
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.
- 12-20-2009, 04:17 PM #3
Senior Member
- Join Date
- Dec 2009
- Posts
- 104
- Rep Power
- 0
oh, first i need to declare the functions?
if i remember correctly you do that like this.
am i right?Java Code:int cadence=2;
- 12-20-2009, 04:21 PM #4
- 12-20-2009, 04:43 PM #5
Senior Member
- Join Date
- Dec 2009
- Posts
- 104
- Rep Power
- 0
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
-
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:
You were confusing the Bicycle class above, with the BicycleDemo class below: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); } }
One thing you'll learn if you stick with programming is that it is not very forgiving. Precision is paramount.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(); } }
Much luck and have fun!
- 12-20-2009, 06:04 PM #7
Senior Member
- Join Date
- Dec 2009
- Posts
- 104
- Rep Power
- 0
Similar Threads
-
XML+Java tutorials?
By MK12 in forum XMLReplies: 4Last Post: 03-19-2011, 01:47 AM -
Chat tutorials
By imperium2335 in forum Java AppletsReplies: 1Last Post: 06-29-2009, 04:39 AM -
Bluetooth Tutorials
By medhat_fci in forum CLDC and MIDPReplies: 1Last Post: 08-11-2008, 03:15 AM -
My tutorials
By gibsonrocker800 in forum Forum LobbyReplies: 2Last Post: 01-06-2008, 07:48 AM -
Tutorials for java, Help
By cachi in forum New To JavaReplies: 1Last Post: 08-06-2007, 06:09 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks