Who knows java?

Discussion in 'Computers and Technology' started by BirdofPrey, Feb 1, 2008.

Who knows java?

Discussion in 'Computers and Technology' started by BirdofPrey, Feb 1, 2008.

  1. BirdofPrey

    BirdofPrey New Member

    Joined:
    Aug 20, 2007
    Messages:
    4,985
    Likes received:
    5
    Trophy points:
    0
    From:
    Arizona
    Because I am Stuck. (if you can't tell form the presence of the UNIX thread I am NOT haing a good time.

    My file won't compile andthe error I get is

    Code:
    Calc.java:28: incompatible types
    found  : double
    required: java.lang.Double
        radius = Double.parseDouble (inputLine);
                      ^
    Calc.java:29: operator * cannot be applied to double,java.lang.Double
        volume = 4 / 3 * Math.PI * radius *radius * radius;
                     ^
    Calc.java:30: operator * cannot be applied to double,java.lang.Double
        surfaceArea = 4 * Math.PI * radius * radius;
                     ^
    
    inputLine is a string and radius is a floating point number.

    I am trying to convert text input to a number to calculate the surface area an volume of a sphere hen output the results
     
  2. Unentschieden

    Unentschieden New Member

    Joined:
    Aug 19, 2007
    Messages:
    481
    Likes received:
    0
    Trophy points:
    0
    What kind of text do you want to convert? I have yet to see a reasonable string -> int/double conversion.
     
  3. BirdofPrey

    BirdofPrey New Member

    Joined:
    Aug 20, 2007
    Messages:
    4,985
    Likes received:
    5
    Trophy points:
    0
    From:
    Arizona
    The program needs to convert whatever number I type in into a floating point number in order to use it in calculations

    This is the prompt we were given:

    Nevermind.  I feel so stupid now.  I capitalized the statements that create the variables



    I do have a questin though.

    When i did the formula for Volume ha to put the 4/3 at the end of the expression to get the right results.

    How come
    Code:
    4 / 3 * Math.PI * radus* radius * radius
    prints out erroneous numbers while
    Code:
    Math.PI * radus* radius * radius * 4 / 3
    give the right answer and how do I make them both do the same thing
     
  4. Mongoose

    Mongoose New Member

    Joined:
    May 22, 2007
    Messages:
    9
    Likes received:
    0
    Trophy points:
    0
    You should use 4.0 and/or 3.0 for the 4/3 part. Integer division is going to give you a wrong answer.
     
  5. Ursawarrior

    Ursawarrior New Member

    Joined:
    Oct 17, 2007
    Messages:
    1,651
    Likes received:
    5
    Trophy points:
    0
    From:
    somewhere....not sure
    ahhh yes................ wait....

    i only know action script 3.0 :p