says im Missing }..?
hello everyone, i just joined these forums. um...i just started learning java today, and i figured out how to use the compiler, but my code seems to me wrong.... can anyone see any errors? its from a book, its the first lesson:P...
class volcanorobot
{
String status;
int speed;
float tempature;
void checktempature(){
if (tempature > 660){
status = "returning home";
speed = 5;
}
}
Void showattributes(){
System.out.println("Status " + status);
System.out.println("Speed: " + speed);
System.out.println("Tempature " + tempature);
}
public static void main(String[] arguments)
{
volcanorobot dante = new volcanorobot();
dante.status = "exploring";
dante.speed = 2;
dante.tempature = 510;
dante.showattributes();
System.out.println("increasing speed to 3.");
dante.speed = 3;
dante.showattributes();
System.out.println("changing tempature to 670");
dante.tempature = 670;
dante.showattributes();
System.out.println("checking the tempature");
dante.checktempature();
dante.showattributes();
}
}
thanks!!, and i'll be back!!...lol
[1283 byte] By [
Booooze] at [2007-9-30 11:24:36]

First - format your reply. See [url=http://forum.java.sun.com/faq.jsp#format]this[/url]
Second - while I can not see anything that should give rise to the error you are getting, there are a couple
of problems that leap out
1. class names by convention start with an uppercase letter, with upper case used for each new word (so your clss name would be VolcanoRobot)
2. your method showattributes returns Void - where it should be void
3. If you want to access the class variables status, speed and temperature from the main, you will need to make them static, or privide "getter" and "setter" methods (the latter is normally preferred)
the corrected version is below
public class VolcanoRobot
{
String status;
int speed;
float tempature;
void checktempature()
{
if (tempature > 660)
{
status = "returning home";
speed = 5;
}
}
void showattributes()
{
System.out.println("Status " + status);
System.out.println("Speed: " + speed);
System.out.println("Tempature " + tempature);
}
public static void main(String[] arguments)
{
VolcanoRobot dante = new VolcanoRobot();
dante.status = "exploring";
dante.speed = 2;
dante.tempature = 510;
dante.showattributes();
System.out.println("increasing speed to 3.");
dante.speed = 3;
dante.showattributes();
System.out.println("changing tempature to 670");
dante.tempature = 670;
dante.showattributes();
System.out.println("checking the tempature");
dante.checktempature();
dante.showattributes();
}
}
type the following commands for compiling it.
javac VolcanoRobot.java
and to run the program
java VolcanoRobot