title: Why are my separate random objects being assigned the same values?
body: <p>sorry for the long post. I suspect my issue is fairly easy to solve but (I think) the code I must post for it to make sense is quite long in length, so I apologize. If there was a way for me to shorten this post while still having it make sense that I'm not aware of, I'd appreciate the feedback.</p>
  <p>I am working on a Java program that simulates a fictional 4-way intersection with stop signs <em>(First St, which runs north/south and Main St, which runs east/west)</em>. I want it to create 4 objects of the Car class, randomize their 3 attributes <em>(1. does it exist? 2. what direction is it traveling? 3. what order did it arrive at the intersection?)</em> using Math.random(), and print them.</p>
  <p>I do exactly this - instantiate 4 cars (car1, car2, car3, car4), randomize their attributes using the randomizeAll method, and then print their attributes using the printState method.. <strong>I expect it to run like this:</strong></p>
  <blockquote>
  <p><strong>Car 1:</strong> This car does not exist.</p>
  <p><strong>Car 2:</strong> This car exists! It is traveling southbound on 1st St. It arrived first.</p>
  <p><strong>Car 3:</strong> This car exists! It is traveling westbound on Main St. It arrived second.</p>
  <p><strong>Car 4:</strong> This car does not exist.</p>
  </blockquote>
  <p>Instead, it runs like some variation of this:</p>
  <blockquote>
  <p><strong>Car 1:</strong> This car exists! It is traveling westbound on Main St. It arrived second.</p>
  <p><strong>Car 2:</strong> This car exists! It is traveling westbound on Main St. It arrived second.</p>
  <p><strong>Car 3:</strong> This car exists! It is traveling westbound on Main St. It arrived second.</p>
  <p><strong>Car 4:</strong> This car exists! It is traveling westbound on Main St. It arrived second.</p>
  </blockquote>
  <p>All four of the cars have the same exact attributes, (although they change each time I re-run the program). I can't figure out what is causing this. There are only 2 things to look at, my main method in the CarDemo class and the Car class itself. My code is as follows:</p>
  <p><strong>CarDemo class, which contains the main method:</strong></p>
  <pre><code>    public class CarDemo {
  
        public static void main(String[] args) {
         
          Car car1 = new Car();
          Car car2 = new Car();
          Car car3 = new Car();
          Car car4 = new Car();
          
          car1.randomizeAll();
          car2.randomizeAll();
          car3.randomizeAll();
          car4.randomizeAll();
          
          System.out.println(&quot;Car 1:&quot;);
          car1.printState();
          
          System.out.println(&quot;Car 2:&quot;);
          car2.printState();
          
          System.out.println(&quot;Car 3:&quot;);
          car3.printState();
          
          System.out.println(&quot;Car 4:&quot;);
          car4.printState();
          
      }
      
  }
  </code></pre>
  <p><strong>The Car class, which contains the randomizeAll and printState methods:</strong></p>
  <pre><code>public class Car {
      
      private static int existence; 
      private static final int EXISTENCEMAX = 1;
      private static final int EXISTENCEMIN = 0;
  
      private static int direction;
      private static final int DIRECTIONMAX = 4;
      private static final int DIRECTIONMIN = 1;
      
      private static int order;
      private static final int ORDERMAX = 4;
      private static final int ORDERMIN = 1;
  
      
      public void randomizeAll() {
          existence = (int)(Math.random() * (EXISTENCEMAX - EXISTENCEMIN + 1) + EXISTENCEMIN);
          direction = (int)(Math.random() * (DIRECTIONMAX - DIRECTIONMIN + 1) + DIRECTIONMIN);
          order = (int)(Math.random() * (ORDERMAX - ORDERMIN + 1) + ORDERMIN);
      
  }
          
      public void printState(){
  
      boolean exist;
      exist = existence == 1;
      if (exist) {
          System.out.println(&quot;This car exists!&quot;);
          switch(direction){
              case 1:
                  System.out.println(&quot;It is traveling northbound on 1st St.&quot;);
                  break;
              case 2:
                  System.out.println(&quot;It is traveling southbound on 1st St.&quot;);
                  break;
              case 3:
                  System.out.println(&quot;It is traveling eastbound on Main St.&quot;);
                  break;
              case 4:
                  System.out.println(&quot;It is traveling westbound on Main St.&quot;);
                  break;
          }
          switch(order){
              case 1:
                  System.out.println(&quot;It arrived first.&quot;);
                  break;
              case 2:
                  System.out.println(&quot;It arrived second.&quot;);
                  break;
              case 3:
                  System.out.println(&quot;It has arrived third.&quot;);
                  break;
              case 4:
                  System.out.println(&quot;It arrived fourth.&quot;);
                  break;
          }           
      } else {
          System.out.println(&quot;This car does not exist.&quot;);
      }  
      
    }    
      
  }
  </code></pre>
  <p>Is anyone able to tell me why each car object shares the same values? I've been staring at this and researching online for several hours and nothing pops out at me. Any input is greatly appreciated. I apologize if my code is messy or redundant in some areas, I am in my very first semester of programming classes so I'm the epitome of a programming noob. Thanks a lot in advance.</p>