title: How to manage state change in Java
body: <pre><code>public void manage()
      {
          double speed = getSpeedfromVehicle();
  
          if(speed &gt;=0 &amp;&amp; speed &lt;= 10)
          {
              System.out.println("Low Speed mode");
          }
          else if(speed &gt; 10 &amp;&amp; speed &lt; 60)
          {
              System.out.println("Medium Speed Mode");
          }
          else if(speed &gt;= 60)
          {
              System.out.println("High Speed Mode");
          }
  
      }
  </code></pre>
  
  <p>When the vehicle starts moving my manage method is called for each and every speed change.
  If the speed stays in one category (0 to 10) i need to print the output statement only once even tough the manage() is called infinite times for speed 0 to 10. This should happen for other speed ranges as well. It also should switch to other speed ranges and should print each speed range only once.</p>