Java newbie - car application
<p>I'm a student and, yes, this is my homework. I've spent the last week reviewing notes, reading the book, and researching related topics on the net, but I just don't get what the problem is. Can you tell me what I'm doing wrong? Any help will be greatly appreciated. (I'm only using notepad and the command prompt.)</p>

<p>The guidelines I was given: Create a Java application consisting of two classes.  Class one will be your application class.  Class two will be a class called Car. Your application will create an instance of Car, called nova, and drive it.   </p>

<p>Rules for the car:</p>

<ul>
<li>You can’t drive  a car if it is not started (send an error message to the console).</li>
<li>You can’t stop a car if it is not started (send an error message to the console).</li>
<li>You can’t start a car if it is already started (send an error message to the console).</li>
<li>Once you tell the car to drive, the only thing you can do is stop (Send a message to the console)</li>
<li>Once you call stop, the car will return to the initial state and the user must start the car before attempting to do any other functions. (Send a message to the console)</li>
</ul>

<p>The purpose of the showState method is provide a way to inspect the state of the car.  It should build a message, which can then be sent to the console.  </p>

<p>My code:</p>

<pre><code>public class MyAppAssignment3
{
   public static void main (String[] args)
   {
       System.out.println("Scenario 1");
       Car nova1 = new Car();
       nova1.start();
       nova1.showState();
       nova1.drive();
       nova1.stop();
       nova1.showState();
       System.out.println("");

       System.out.println("Scenario 2");
       Car nova2 = new Car();
       nova2.showState();
       nova2.drive();  //needs to send error message - can't drive a car that's not started
       nova2.stop();
       nova2.showState();
       System.out.println("");

       System.out.println("Scenario 3");
       Car nova3 = new Car();
       nova3.showState();
       nova3.start();
       nova3.showState();
       nova3.stop();   //needs to send error message - can't stop a car that's not driving
       nova3.showState();
       nova3.drive();
       nova3.stop();
   }
}

class Car
{
   private boolean isStarted;
   private boolean isDriving;
   private boolean isStopped;
   private String showState;

   public Car()
   {
       this.showState = showState;
   }

   public void start()
   {
       isStarted = true;
       isDriving = false;
       isStopped = false;
       System.out.println("The car is " + this.showState);
   }

   public void drive()
   {
       isStarted = false;
       isStopped = false;
       isDriving = true;
       System.out.println("The car is " + this.showState);
   }

   public void stop()
   {
       isStopped = true;
       isStarted = false;
       isDriving = false;
       System.out.println("The car is " + this.showState);
   }

   public String showState()
   {
       if (isStarted)
       {
           showState = "started";
       }
       else if(isDriving)
       {
           showState = "driving";
       }
       else if(isStopped)
       {
           showState = "stopped";
       }
       System.out.println("The car is " + this.showState);
       return showState;
   }
}
</code></pre>

<p>My output (which is all wrong - the values are incorrect):</p>

<pre><code>Scenario 1
The car is null
The car is started
The car is started
The car is started
The car is stopped

Scenario 2
The car is null
The car is null
The car is null
The car is stopped

Scenario 3
The car is null
The car is null
The car is started
The car is started
The car is stopped
The car is stopped
The car is stopped
</code></pre>

<p>Sorry if this posted all wonky. I typed it fine but the preview looks screwy.</p>
