title: How to use random number generator with if statements
body: <p>so I am making a text-based game, and I want to use a random number generator to say if the random number that it generates is 3, that it will say that a certain monster has appeared. For some reason it is having trouble allowing me to do an if statement for the random number. Here is the code:</p>
  
  <pre><code>import java.util.Random;
  import java.util.Scanner;
  public class mainClass 
  {
      public static void main(String args[])
      {
          Scanner input = new Scanner(System.in);
  
          String username, character_type, testing_enemy;
  
          //Variables for spells
          double mage_fire, mage_iceblast, mage_voidray;
          double warrior_uppercut, warrior_kick, warrior_hook;
          double archer_diamond, archer_power, archer_precision;
  
          //variables for base stats
          int base_health, base_spell_dmg, base_attack_dmg, base_mana;
  
          //variable for random number generator
          int number = Integer.parseInt(testing_enemy);
  
          System.out.println("Welcome to Realm Of Worlds!");
          System.out.println("Enter username: ");
          username = input.nextLine();
          System.out.println();
          System.out.println("Welcome to Realm Of Worlds " + username);
          System.out.println("Realm Of Worlds is an interactive text based game "
                  + "that allows you to fight monsters and buy items and spells to get even stronger.");
          System.out.println("Would you like to be a Mage, a Warrior, or an Archer?");
          character_type = input.nextLine();
  
  
          if(character_type.equals("mage") || character_type.equals("Mage"))
          {
              System.out.println("Ok, " + username + " you are now a " + character_type + "!");
  
              base_health = 850;
              base_spell_dmg = 60;
              base_attack_dmg = 50;
              base_mana = 500;
  
              System.out.println("As a Mage, you have " + base_health + " base health, " + base_spell_dmg + " base spell damage, " + base_attack_dmg + " base attack damage, and " + base_mana + " base mana.");
              System.out.println("Your spells are Fire Blast, Ice Blast, and Void Ray.");
              System.out.println("All of your spells do Spell Damage, so focus on building Spell Damage Items");
  
              mage_fire = (30 + (.60*base_spell_dmg));
              mage_iceblast = (50 + (.45*base_spell_dmg));
              mage_voidray = (45 + (.55*base_spell_dmg));
  
              System.out.println("Would you like to use 1. Fire Blast, 2. Ice Blast, 3. Void Ray? (Just type 1, 2, or 3)");
  
          }
  
  
          if(character_type.equals("warrior") || character_type.equals("Warrior"))
          {
              System.out.println("Ok, " + username + " you are now a " + character_type + "!");
  
              base_health = 1000;
              base_spell_dmg = 20;
              base_attack_dmg = 80;
              base_mana = 300;
  
              System.out.println("As a Warrior, you have " + base_health + " base health, " + base_spell_dmg + " base spell damage, " + base_attack_dmg + " base attack damage, and " + base_mana + " base mana.");
              System.out.println("Your spells are Uppercut, Kick, and Hook Punch");
              System.out.println("All of your spells do Attack Damage, so focus on building Attack Damage Items");
  
              warrior_uppercut = (30 + (.55*base_attack_dmg));
              warrior_kick = (50 + (.45*base_attack_dmg));
              warrior_hook = (45 + (.50*base_attack_dmg));
          }
  
          if(character_type.equals("archer") || character_type.equals("Archer"))
          {
              System.out.println("Ok, " + username + " you are now a " + character_type + "!");
  
              base_health = 700;
              base_spell_dmg = 40;
              base_attack_dmg = 70;
              base_mana = 400;
  
              System.out.println("As an Archer, you have " + base_health + " base health, " + base_spell_dmg + " base spell damage, " + base_attack_dmg + " base attack damage, and " + base_mana + " base mana.");
              System.out.println("Your spells are Diamond Arrow, Power Shot, and Precision Eye");
              System.out.println("Also, as archer, you have a passive ability of dodging 1 in every 6 attacks from an opponent");
              System.out.println("Your spells do a combination of Spell and Attack Damaeg, so it is worth building both types of items, but more Attack Damage is done than Spell Damage");
  
              archer_diamond = (30 + ((.35*base_attack_dmg)+(.20*base_spell_dmg)));
              archer_power = (50 + ((.30*base_attack_dmg)+(.15*base_spell_dmg)));
              archer_precision = (45 + ((.35*base_attack_dmg)+(.15*base_spell_dmg)));
          }
  
          //Setting up enemy randomization
          **Random dice = new Random();
  
          for(int counter=1; counter&lt;=3; counter++)
          {
              number = 1+dice.nextInt(3);
  
              if(number.equals(3))
              {
                  System.out.println("A monster appeared!!");
              }**
          }
      }
  }
  </code></pre>