I am in way over my head...

Discussion in 'Software' started by anomalous, Dec 1, 2008.

  1. anomalous

    anomalous Private E-2

    Hi I am in deep trouble..
    I am in my last week of my semester trying to do a lab and I am hopelessly stuck on one little detail and this is killing my future..I need some good advice to kind of help me over this hurdle..because getting it from teachers and teaching assistants suck..

    I have this code
    while(!isValid(strNum,0,100){
    strNum =JOptionPane.showInputDialog(null,"Error -enter no.. of..etc..", "Km",JOptionPane.QUESTION_MESSAGE);
    }
    Then this method is supposed to jump to..
    public static boolean isValid(String strNum, double min1, max1){

    boolean valid = true;
    if (isValid(strNum,min1,max1)){
    double isValid =Double.parseDouble(strNum);
    valid = true
    if (isValid < min1 || isValid > max1)
    {
    valid = false; //value is not a valid double
    }else{
    valid = false;// set flag to false
    }//closes inside if

    }//closes outside if

    //return flag
    return valid;

    }//close isValid method
    ok the problem is..the code compiles..but the method doesn't do its job..
    I want isValid method to be jumped to ..so that if the return value is false it will stay in a loop until a proper value is entered. A true valid value will cause a jump out of the loop so I can continue with calculations and such. I know I have to use exceptions in here somewhere I just need an idea of how to structure the placing of them so I don't get errors. Basically I want to keep trying to input a value until the computer accepts it as valid. Then I can use it to calculate my results. Trick is the isValid method command is doing something kooky like spitting out a long list of lines on the console referring to line

    if (isValid(strNum,min1,max1)){

    Also the boolean not symbol isn't helping either. I only learned methods a week before I had to write all this crap and now I am stuck..
    So...HeEEELLLlllLLLLPPP!!.. I would much appreciate it..maybe even owe you my first born...(jK) but who knows..lol:cry
     
  2. PC-XT

    PC-XT Master Sergeant

    Generally, forums like this let students figure it out themselves or ask qualified instructors, but here are general pointers I have for these situations: I use the comment-out techniques to narrow down problem code (if you've covered this). I set the problem aside and do something in another subject, like recess lol, and come back, hopefully after I've forgotten whatever error I was thinking to try again. If that doesn't work, I forget the old code, and calmly and carefully rewrite from scratch, which strangely often works. Am I as bad as a teaching assistant?
     
  3. anomalous

    anomalous Private E-2

    thanks for the tips..
    your advice comes in handy..I have been making headway
    anything from any source is useful either as new information or as reinforcement for old learning to push one out of rut..

    again

    thanks!

    :cool
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds