title: How does one use an if statement on object oriented programming (preferably in Java)?
body: <p>How does one use an if statement on object oriented programming (preferably in Java)?</p>
  
  <pre><code>import java.util.*;
  class item 
  {
      Random rand = new Random();
      int chance = rand.nextInt(20);
      String name;
      double price;
      {
          if (chance &lt;= 20){
               price = price * 0.70 ;
          }
      }
  }
  
  
  public class tutorial{
  public static void main (String[] args)
  {   
  
      item i1 = new item();   
      item i2 = new item();
  
      i1.name = "Soda";
      i1.price = 5;
  
      i2.name = "Candy";
      i2.price = 2;
  
  
  
      System.out.println ("Name : " + i1.name + 
              " Price : " + i1.price );
      System.out.println ("Name : " + i2.name + 
              " Price : " + i2.price );
  }
  }
  </code></pre>
  
  <p>I want to:</p>
  
  <ul>
  <li>Create a random generator in the item class</li>
  <li>The random generator in the item class should effect the price in the main tutorial class</li>
  <li>If the chance variable is between 1 to 20 slash the price by30%</li>
  <li>It has to work with item 1 &amp; 2</li>
  </ul>
  
  <p><strong>Note:</strong> I do not want to do it in the tutorial class because I will have to perform the if statement for chance fore each code. Hopefully that helps.</p>