Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

about enum  RSS feed

 
srikanth arroju
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please explain about enum
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://www.google.com/search?q=java+enum
 
Campbell Ritchie
Marshal
Posts: 55681
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.
I presume you have learnt to find your way round the Java tutorial? Then you will have found this part about "enums."

CR
 
srikanth arroju
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
iam gettin an error of
Planet.java:38: 'class' or 'interface' expected
when i tried the program
please help me
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16026
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using Java 5.0? Enum is a new feature introduced in Java 5.0. You cannot use it if you are using an older version of Java (1.4 or older).

If you are using Java 5.0, please post your source code - it's difficult to know what's happening if you don't show us what you're trying to compile.
 
srikanth arroju
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public enum Planet{
MERCURY (3.303e+23, 2.4397e6),
VENUS (4.869e+24, 6.0518e6),
EARTH (5.976e+24, 6.37814e6),
MARS (6.421e+23, 3.3972e6),
JUPITER (1.9e+27, 7.1492e7),
SATURN (5.688e+26, 6.0268e7),
URANUS (8.686e+25, 2.5559e7),
NEPTUNE (1.024e+26, 2.4746e7),
PLUTO (1.27e+22, 1.137e6);
private final double mass;
private final double radius;
Planet (double mass, double radius)
{
this.mass = mass;
this.radius = radius;
}
public double mass()
{
return mass;
}
public double radius()
{
return radius;
}
public static final double G = 6.67300E-11;
public double surfaceGravity()
{
return G*mass / (radius*radius);
}
public double surfaceWeight (double otherMass)
{
return otherMass * surfaceGravity();
}
}


public static void main(String[] args)
{
double earthWeight = Double.parseDouble(args[0]);
double mass = earthWeight/EARTH.surfaceGravity();
for (Planet p : planet.values() )
{
System.out.printf("Your weight is on %s is %f%n",p,p.surfaceWeight(mass));
}
}
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16026
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you are using Java 5.0?

You have misplaced the closing curly braces. You have one extra } after the method surfaceWeight and you are missing a } at the end.

[edit]: And also, this line is wrong:

for (Planet p : planet.values() )

You should have used a capital P:

for (Planet p : Planet.values() )
[ August 03, 2006: Message edited by: Jesper Young ]
 
srikanth arroju
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks its working
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!