java - Code just finishes without thoroughly processing -


this beginner error new java , programming in general. anyways, thought placement of system.exit(0) in code, when switched elsewhere there error i'm sure it's right. code ask first joptionpane.showinputdialog. when enter yes response, code finishes processing , nothing else. causing code end instead of processing dice event?

    import javax.swing.joptionpane;  /**    fishing class simulates game of fishing. */  public class fishing {    public static void main(string[] args)    {       string input = joptionpane.showinputdialog("would play round " +                                                     "of fishing? enter yes or no?");        while (input == "yes")       {          int score = 0;   // sets player's score 0          int points = 0;      // holds player's points          final int die_sides = 6;    // # of sides die           //create instance of die class          die die = new die(die_sides);           //roll die once , store value in result          die.roll();          int result = die.getvalue();           //call getscore method , pass points , result          getscore(points, result);           //keeps running total of player's score          score = score + points;       }        system.exit(0);    }      /**       getscore method calculate player's score       depending on player rolled. show       message , return score.       @return reference integer object containing               player's score 1 roll.    */     public static int getscore(int points, int result)    {       if (result == 1)       {          joptionpane.showmessagedialog(null, "waaaaahhhhh, have caught " +                                        "a shark. sharks dangerous. " +                                             "have been awarded 0 points.");          points = 0;          return points;       }       else if (result == 2)       {          joptionpane.showmessagedialog(null, "you have caught jellyfish. " +                                   "this beautiful creature has awarded " +                                                                "50 points!!");          points = 50;          return points;       }       else if (result == 3)       {          joptionpane.showmessagedialog(null, "you have caught old boot. " +                                 "maybe can sell old boot after " +                                  "dries out. have been awarded 1 point.");          points = 1;          return points;       }       else if (result == 4)       {          joptionpane.showmessagedialog(null, "you have caught alaskan salmon. " +                                 "this delicious , popular fish has awarded " +                                                                     "75 points!!!");          points = 75;          return points;       }         else if (result == 5)       {          joptionpane.showmessagedialog(null, "you have caught small fish. " +                                                    "have been awarded 20 points!");                                                                                          points = 20;          return points;       }       else       {          joptionpane.showmessagedialog(null, "you have caught treasure chest!! " +                                   "it filled shining pieces of gold, , " +                                             "you have been awarded 100 points!!!!");          points = 100;          return points;       }    } } 

this die class.

import java.util.random;   /**    die class simulates rolling of die. */  public class die {    private int sides;    //number of sides    private int value;    //the die's value     /**       constructor performs initial roll of die.       @param numsides number of sides die.    */     public die(int numsides)    {      sides = numsides;      roll();    }     /**       roll mthod simulates rolling of die.    */     public void roll()    {       //create random object.       random rand = new random();        //get random value die.       value = rand.nextint(sides) + 1;    }     /**       getsides method       @return number of sides die.    */     public int getsides()    {       return sides;    }     /**       getvalue method       @return value of die.    */     public int getvalue()    {       return value;    } } 

first of change below , try

 while (input == "yes") 

to

 while (input.equals("yes")) 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -