Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 19 of 19

Thread: double to int problem...

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default double to int problem...

    This junk won't work idk wtf is wrong with it. Mainly a double to int issue, can someone say what's up?

    void


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: double to int problem...

    This junk won't work
    Please explain what "won't work" means? Show the program's output and explain what is wrong with it.
    If there are errors, please copy the full text of the messages and paste them here.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: double to int problem...

    The problem is simple, I am using both ints and doubles and I apparently have to choose. The problem is that, while many of my variables are ints like DAT PAR SYS DAM PAM, some are doubles because they are not integers, like refluxRatio. My question is, if I want to put 0.3 reflux ratio for example, it tell me it's not an int...but I know it's not an int, it CANNOT be an int, it's a fkn ratio!!!!! So how do I make the compiler happy? How do I pass a 0.3 value?

    Is it possible for me to convert everything into double? Will that be possible for a 2 dimensional array? Because there's loop counters like i, that have to be ints, so is it gona tell me, oh no we cant take ur doubles because the fkn counter is an int? Help please!

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: double to int problem...

    want to put 0.3 reflux ratio for example, it tell me it's not an int.
    0.3 is a double and needs to be handled as a double. If you cast it to an int it will be 0
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Dec 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: double to int problem...

    yes but then it tells me double to int mismatch...it wants both to be doubles or both to be int, you must have heard of this error before, idk how to explain it more...the loss of information thing? What should I do?

  6. #6
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: double to int problem...

    What line(s) is the compiler complaining about?

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: double to int problem...

    it tells me double to int mismatch
    Please post the full text of the error message.

    .the loss of information
    Converting 0.3 to int would give 0
    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Junior Member
    Join Date
    Dec 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: double to int problem...

    I also get a "The field DistillationColumn.feedTray is not visible" thing for the super variables, super class:

  9. #9
    Junior Member
    Join Date
    Dec 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: double to int problem...

    Quote Originally Posted by Norm View Post
    Please post the full text of the error message.


    Converting 0.3 to int would give 0
    File: F:\Flash Tank 2\Flash Tank\BinaryDistillation.java [line: 31]
    Error: The field DistillationColumn.feedTray is not visible
    File: F:\Flash Tank 2\Flash Tank\BinaryDistillation.java [line: 39]
    Error: The field DistillationColumn.feedTray is not visible
    File: F:\Flash Tank 2\Flash Tank\BinaryDistillation.java [line: 39]
    Error: The field DistillationColumn.trays is not visible
    File: F:\Flash Tank 2\Flash Tank\BinaryDistillation.java [line: 51]
    Error: The field DistillationColumn.trays is not visible
    File: F:\Flash Tank 2\Flash Tank\BinaryDistillation.java [line: 64]
    Error: The field DistillationColumn.feedTray is not visible
    File: F:\Flash Tank 2\Flash Tank\BinaryDistillation.java [line: 65]
    Error: The field DistillationColumn.feedTray is not visible
    File: F:\Flash Tank 2\Flash Tank\BinaryDistillation.java [line: 66]
    Error: The field DistillationColumn.trays is not visible
    File: F:\Flash Tank 2\Flash Tank\BinaryDistillation.java [line: 75]
    Error: The field DistillationColumn.refluxRatio is not visible
    File: F:\Flash Tank 2\Flash Tank\BinaryDistillation.java [line: 78]
    Error: The field DistillationColumn.refluxRatio is not visible
    File: F:\Flash Tank 2\Flash Tank\Chemicals.java [line: 37]
    Error: The left-hand side of an assignment must be a variable
    File: F:\Flash Tank 2\Flash Tank\Chemicals.java [line: 46]
    Error: The left-hand side of an assignment must be a variable
    File: F:\Flash Tank 2\Flash Tank\DistillationColumn.java [line: 1]
    Error: The type DistillationColumn must be an abstract class to define abstract methods
    File: F:\Flash Tank 2\Flash Tank\DistillationColumn.java [line: 1]
    Error: The type DistillationColumn must implement the inherited abstract method Equation.evaluateEquations(double, Stream)
    File: F:\Flash Tank 2\Flash Tank\DistillationColumn.java [line: 23]
    Error: The abstract method clone in type DistillationColumn can only be defined by an abstract class
    --------------
    ** Warnings **
    --------------
    File: F:\Flash Tank 2\Flash Tank\BinaryDistillation.java [line: 9]
    Warning: The field BinaryDistillation.str is never read locally
    File: F:\Flash Tank 2\Flash Tank\BinaryDistillation.java [line: 10]
    Warning: The field BinaryDistillation.q is never read locally

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: double to int problem...

    Any idea what "not visible" means?
    That doesn't look like any compiler error message I've seen.
    The variable in the message is private to the class its defined in.

    Please post the full text of the compiler's error messages.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Dec 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: double to int problem...

    Done, sorry I should have posted the error log before XD

    --- Update ---

    the trays is in the super constructor, I don't understand wtf is the problem ((

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: double to int problem...

    the trays is in the super constructor
    Can you explain what the problem is?
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Dec 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: double to int problem...

    The problem is that the program doesnt run because of the error I posted above. I want the program to run so I can go home and party

    --- Update ---

    Error: The field DistillationColumn.feedTray is not visible

    --- Update ---

    OHHHHHHHHHHHHHHHH I forgot the get accessor rofl! XD

    P.S. Hmm, don't mean to be rude but, you guys know any Java at all lol? I'm getting weird feedback here haha

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: double to int problem...

    The field is private. It can not be accessed from outside of the class.
    Add a get method to the class to read that field's value and return it to the caller.

    You should spend more time reading the code and less posting.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Junior Member
    Join Date
    Dec 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: double to int problem...

    Isuck at Java man, doesn't help me to read, plus I got ADHD which makes reading even worst ^_______^

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: double to int problem...

    You'll have a hard time with programming if you can't read and understand documentation.
    There is too much to remember so you have to read the API doc to get the details .
    I read the API doc many times a day.
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Junior Member
    Join Date
    Dec 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: double to int problem...

    In case you haven't noticed I'm a chemical engineer and the only reason I gotta do programming is because of my stupid pos program which requires us to do so. I don't care if they find this, I'm on a proxy so they won't know who wrote it anyways rofl.

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: double to int problem...

    If you're done, Please mark this thread as solved
    If you don't understand my answer, don't ignore it, ask a question.

  19. #19
    Junior Member
    Join Date
    Dec 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: double to int problem...

    idk how, I'm noob

Similar Threads

  1. Replies: 9
    Last Post: August 30th, 2012, 03:25 PM
  2. "possible loss of precision, found double, required int" HELP
    By kkatchh in forum Loops & Control Statements
    Replies: 3
    Last Post: November 6th, 2011, 10:50 AM
  3. Possible loss of precision (double/int)
    By haloboy in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 8th, 2011, 02:23 AM
  4. int / double validation
    By exnuke1972 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 20th, 2011, 05:08 PM
  5. [SOLVED] Loss of Precision (Double/Int)
    By Scotty in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 9th, 2010, 01:45 PM