Computer problems,Computer help
*AX SOFT>>>Programming & Design

I need to enter a string with a decimal to change to a double?


i know about the Double.parseDouble but it isn't working

import javax.swing.JOptionPane;

public class Circles
{
public static void main(String args[])
{
String input = JOptionPane.showInputDialog("Please Choose An Option\n" + "1. Area\n" + "2. Circumference\n" + "3. Area of a sector\n" + "4. Arc Length\n" + "5.Exit");

if (input.compareTo("1")==0)
{
runArea();
}
else if (input.compareTo("2")==0)
{
runCircumference();
}
else if (input.compareTo("3")==0)
{
runSector();
}
else if (input.compareTo("4")==0)
{
runArc();
}
else if (input.compareTo("5")==0)
{
System.out.println("Good Bye");
System.exit(0);
}
else
{
System.out.println("Error");
System.exit(0);
}

}
public static void runArea()
{
String input1 = JOptionPane.showInputDialog("Enter radius");
double radius = Integer.parseInt(input1);
double area = radius*radius*3.14;
System.out.println("Area = " + area);
}

public static void runCircumference()
{
String input2 = JOptionPane.showInputDialog("Enter radius");
double radius1 = Integer.parseInt(input2);
double circumference = 2*radius1*3.14;
System.out.println("Circumference = " + circumference);
}

public static void runSector()
{
String input3 = JOptionPane.showInputDialog("1. Radians\n" + "2.Degrees");

if (input3.compareTo("1")==0)
{
String input4 = JOptionPane.showInputDialog("Enter radius");
String input5 = JOptionPane.showInputDialog("Enter radians");
double radius2 = Integer.parseInt(input4);
double radian = Integer.parseInt(input5);
double sector= 0.5*radius2*radius2*radian;//check lata
System.out.println("Area of Sector = " + sector);


}
else if (input3.compareTo("2")==0)
{
String input6= JOptionPane.showInputDialog("Enter radius");
String input7= JOptionPane.showInputDialog("Enter degrees");
double radius3 = Integer.parseInt(input6);
double degree = Integer.parseInt(input7);
double sector1= degree/360*3.14*radius3*radius3;
System.out.println("Area of Sector = " + sector1);

}
else
{
System.out.println("Error");
System.exit(0);
}
}
public static void runArc()
{
String input8 = JOptionPane.showInputDialog("1. Using Radians\n"+"2. Using Degrees.");
if(input8.compareTo("1")==0)
{
String input9 = JOptionPane.showInputDialog("Enter radius");
String input10 = JOptionPane.showInputDialog("Enter radians");
double radius4 = Integer.parseInt(input9);
double radian2 = Integer.parseInt(input10);
double arc = radius4*radian2;
System.out.println("Arc Length = " + arc);
}
else if(input8.compareTo("2")==0)
{
String input11 = JOptionPane.showInputDialog("Enter radius");
String input12 = JOptionPane.showInputDialog("Enter degrees");
double radius5 = Integer.parseInt(input11);
double degree2 = Integer.parseInt(input12);
double arc1 = degree2*3.14/180*radius5;
System.out.println("Arc Length =" + arc1);
}
else
{
System.out.println("Error");
System.exit(0);
}

}
}

When you say that Double.parseDouble does not work what exactly do you mean?

Print the String before you do the parse. Add a character before and after like
System.out.println("#" + myString + "#");
so that you know exactly what you are trying to parse.
If you do not get an exception then print the result of the parse.

Tags
  General - Computers & Internet   Software   Security   Programming & Design   Facebook   Flickr   Google   MSN   MySpace
Related information
  • MS Word - themes & background applied to 1 page only ?

    Hi there, By default Word puts the watermark in the header and also by default the same header on each page of the document. In order to change that, after you have added your watermark to t...

  • How to make a website for free (with very limited knowledge)?

    Free domains do not exist because the company that is selling a domain (e.g. godaddy.com) has to pay VeriSign and ICANN to register your domain. If you really want your own domain I reccomend buyin...

  • Visual Studios 2008 C# question?

    the opacity percent is actually supposed to be a decimal number less than 1. so for 50 percent try object.opacity=0.5f; I think that should work. Regards! -Mr. Bob

    ...
  • What is the best way to make a website, for free, NO MONEY, and it's all online.?

    long term steady income require some patience and dedication.. fast n easy money r mostly scams.. I have been successful with adsense and pretty happy with it till now, Its free to start with so n...

  • Java Line Segment Intersection?

    The following is an algorithm, not a program. I hope it helps. ------------ Let there be two line segments S12 and S34. Let S12 have endpoints (x1,y1) and (x2, y2). Let S34 have endpoints (x3...

  • Html help plz?

    (note the position of the slash) or <p>Your text</p><p>Some other text </p>

    ...
  • What site or what do i do to make a clickable drop down menu?

    ...

  • Help with Fireworks CS3?

    you need to install that plug in that you can find at the CD software shop. it is the Adobe plug in.

    ...
  •  

    Categories--Copyright/IP Policy--Contact Webmaster