4 Replies - 1597 Views - Last Post: 24 September 2010 - 07:38 AM Rate Topic: -----

#1 Guest_Jeff*


Reputation:

Need help with this error!

Posted 23 September 2010 - 10:59 PM

I need help with this compile error.

"The method parseDouble(String) in the type Double is not applicable for arguments (double)"

Here's my code.
import java.awt.Graphics;
import javax.swing.JApplet;
import javax.swing.JOptionPane;

public class Assign3 extends JApplet
{
private double diameter;
private double circum;
private double area;

public void init()
{
String radius = JOptionPane.showInputDialog(
"Enter the radius of the circle" );

double radius1 = Double.parseDouble( radius1 );

double diameter;
double circum;
double pi = Math.PI;
double area;

diameter = 2*radius1;
circum = 2*(pi*radius1);
area = 2*pi*(radius1*radius1);
}

public void paint( Graphics g )
{
super.paint( g );

String radius = null;
g.drawString( "The radius is " + radius , 25, 25);
g.drawString( "The diameter is " + diameter , 25, 35);
g.drawString( "The circumference is " + circum , 25, 45);
g.drawString( "The area is " + area , 25, 55);
}
}



Edited by macosxnerd101: Please, :code:.

Is This A Good Question/Topic? 0

Replies To: Need help with this error!

#2 javadork  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 32
  • View blog
  • Posts: 135
  • Joined: 21-August 10

Re: Need help with this error!

Posted 23 September 2010 - 11:15 PM

It looks like you are mistakenly referencing the wrong radius in your parseDouble method. Try using 'radius' instead of 'radius1'.

String radius = JOptionPane.showInputDialog("Enter the radius of the circle" );
double radius1 = Double.parseDouble( radius1 );


This post has been edited by javadork: 23 September 2010 - 11:15 PM

Was This Post Helpful? 0
  • +
  • -

#3 Guest_Jeff*


Reputation:

Re: Need help with this error!

Posted 23 September 2010 - 11:35 PM

import java.awt.Graphics;
import javax.swing.JApplet;
import javax.swing.JOptionPane;

public class Assign3 extends JApplet
{
private double diameter;
private double circum;
private double area;
private double pi = Math.PI;
private double radius;

public void init()
{
String radius = JOptionPane.showInputDialog(
"Enter the radius of the circle" );

double radius1 = Double.parseDouble( radius );
radius = radius;
diameter = 2*radius1;
circum = 2*(pi*radius1);
area = pi*(radius1*radius1);
}
public void paint( Graphics g )
{
super.paint( g );
g.drawString( "The radius is " + radius , 25, 25);
g.drawString( "The diameter is " + diameter , 25, 45);
g.drawString( "The circumference is " + circum , 25, 65);
g.drawString( "The area is " + area , 25, 85);
}
}


This post has been edited by macosxnerd101: 24 September 2010 - 08:15 AM
Reason for edit:: Added code tags. Please use them in the future.

Was This Post Helpful? 0

#4 Guest_Jeff*


Reputation:

Re: Need help with this error!

Posted 23 September 2010 - 11:39 PM

That's the code i have now. It works fine except the radius result shows 0 even though the user inputs it.
Was This Post Helpful? 0

#5 guido-granobles  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 171
  • View blog
  • Posts: 617
  • Joined: 02-December 09

Re: Need help with this error!

Posted 24 September 2010 - 07:38 AM

The problem is that you declare the radius attribute as doble at the top of the class:
private double radius;


And you also have the raduis variable inside of the init method:
public void init()
{
  String radius = JOptionPane.showInputDialog(
  "Enter the radius of the circle" );


I think you should do this:
String strRadius = JOptionPane.showInputDialog(
"Enter the radius of the circle" );

radius = Double.parseDouble( strRadius );


In this way you will be assigning the double value contained in the strRadius variable to the radius attribute of the class.

Remove this line:
radius = radius;


Because that line does not make sense. Since the radius string inside the method init override the radius attribute of the class. So doing radius=radius does not make anything. And do not forget use radius instead of radius1 in order to calculate the diameter, circum and area.

This post has been edited by guidojavier: 24 September 2010 - 07:42 AM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1