need little java help
Page 1 of 1
Przepraszam
VIP Member



Posts: 14398
Location: Poland. New York.
PostPosted: Sat, 21st Feb 2009 21:11    Post subject: need little java help
I suppose to write program that calculates are of circle using JOption to display input dialog boxes but I have run to some problem that I can not figure out

Code:
import javax.swing.JOptionPane;

public class AreaBox {
   public static void main(String[] args) {
      // Enter area
      String RadiusString = JOption.showInputDialog( "Enter radius, for example 2.0: ");
            
      // Convert string to double
      double Radius =
         Double.parseDouble(RadiusString);
      final double PI = 3.14;
      double area = Radius * Radius * PI;
      
      // Display Result
      String output = "The area of circle with radius of" + Radius + " is " + double area;
      JOptionPane.ShowMessageDialog(null, output);
   }
}


sorry but im a noob, currently taking programming I...guy gave us 6 programs to write and I'm kinda stuck on this one..JCreater says problem is somewhere in line 15 but I have no idea what seems to be the problem, I followed examples and in the book and not what


Back to top
LeoNatan
Banned



Posts: 73193
Location: Ramat Gan, Israel 🇮🇱
PostPosted: Sat, 21st Feb 2009 21:16    Post subject:
Code:
import javax.swing.JOptionPane;

public class AreaBox {
   public static void main(String[] args) {
      // Enter area
      String RadiusString = JOption.showInputDialog( "Enter radius, for example 2.0: ");
           
      // Convert string to double
      double Radius =
         Double.parseDouble(RadiusString);
      final double PI = 3.14;
      double area = Radius * Radius * PI;
     
      // Display Result
      String output = "The area of circle with radius of" + Radius + " is " + area;
      JOptionPane.ShowMessageDialog(null, output);
   }
}


"double area" declares a double precision variable called "area". When you want to use it, you only have to use the name "area".
Back to top
lhzr




Posts: 3902
Location: RO
PostPosted: Sat, 21st Feb 2009 21:20    Post subject:
also you can use Math.PI instead of declaring a constant equal to 3.14
Back to top
Przepraszam
VIP Member



Posts: 14398
Location: Poland. New York.
PostPosted: Sat, 21st Feb 2009 21:31    Post subject:
iNatan, that code does not work, now I get errors in line 6 and line 16, so I take that whole program might be fucked up

haha lhzr, gonna take it slow, just learning basics for now ;p but it looks like i cant even get basics right


Back to top
LeoNatan
Banned



Posts: 73193
Location: Ramat Gan, Israel 🇮🇱
PostPosted: Sat, 21st Feb 2009 21:53    Post subject:
Care to post the errors? Smile
Back to top
lhzr




Posts: 3902
Location: RO
PostPosted: Sat, 21st Feb 2009 22:17    Post subject:
at line 6, replace JOption with JOptionPane
Back to top
Przepraszam
VIP Member



Posts: 14398
Location: Poland. New York.
PostPosted: Sat, 21st Feb 2009 22:17    Post subject:
ok, but stil get error at line 16

E:\CSCI-120\AreaBoxV2.java:16: cannot find symbol
symbol : method ShowMessageDialog(<nulltype>,java.lang.String)
location: class javax.swing.JOptionPane
JOptionPane.ShowMessageDialog(null, output);
^
1 error

Process completed.


Back to top
lhzr




Posts: 3902
Location: RO
PostPosted: Sat, 21st Feb 2009 22:19    Post subject:
also, if you import the javax.swing.JOptionPane package, there's no need to put JOptionPane. in front of JOptionPane members, like showInputDialog or showMessageDialog
you can write directly smth like this: String RadiusString = showInputDialog...


Last edited by lhzr on Sat, 21st Feb 2009 22:21; edited 1 time in total
Back to top
lhzr




Posts: 3902
Location: RO
PostPosted: Sat, 21st Feb 2009 22:20    Post subject:
java is case sensitive, put showMessageDialog instead of ShowMessageDialog

check proper syntax here: http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JOptionPane.html
Back to top
Przepraszam
VIP Member



Posts: 14398
Location: Poland. New York.
PostPosted: Sat, 21st Feb 2009 22:22    Post subject:
I got it

its not

Code:
JOptionPane.ShowMessageDialog(null, output);


but its

Code:
JOptionPane.showMessageDialog(null, output);


smaller case s instead of upper case S

thanks again, this 1400 page book gives me shivers everytime I look at it but reading is fundamental


Back to top
LeoNatan
Banned



Posts: 73193
Location: Ramat Gan, Israel 🇮🇱
PostPosted: Sun, 22nd Feb 2009 00:18    Post subject:
Yeah, Java uses that ugly ugly ugly naming conventions, where all methods start with a lowercase letter.
Back to top
Page 1 of 1 All times are GMT + 1 Hour
NFOHump.com Forum Index - Programmers Corner
Signature/Avatar nuking: none (can be changed in your profile)  


Display posts from previous:   

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2.0.8 © 2001, 2002 phpBB Group