title: Connecting two classes
body: <p>I'm stuck on this one exercise where I should create a second class called Car, that is linked to Vehicle. This is how it should look:</p>
  
  <p><a href="https://i.stack.imgur.com/Ziqsd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ziqsd.png" alt="https://gyazo.com/4c0c5c29fb7dec32080f3ce59383c320"></a></p>
  
  <p>The vehicle class along with the testprogram works great, but now I want to connect the class Car to the vehicle, and then create a testclass for car. This is my vehicle class:</p>
  
  <pre><code>public class Vehicle {
  int speed;
  
  // Constructor
  public Vehicle() {
      this.speed = 0;
  
  }
  
  public class Car extends Vehicle {
      String regnr;
  
      public Car(String regnr) {
          this.regnr = regnr;
      }
  
      public String getRegNbr() {
          return this.regnr;
      }
  
  }
  
  public void increaseSpeed(int differenceInc) {
      int currentSpeed = this.speed;
      // Kör loopen så länge den nuvarande hastigheten inte är lika med den önskade
      while (this.speed != (currentSpeed + differenceInc)) {
          this.speed += 1;
  
          System.out.println("The current speed is increasing to: " + this.speed);
      }
  
  }
  
  public void decreaseSpeed(int differenceDec) {
      int currentSpeed = this.speed;
  
      while (this.speed != (currentSpeed - differenceDec)) {
          this.speed -= 1;
          System.out.println("The current speed is decreasing to: " + this.speed);
      }
  
  }
  
  public void brake() {
      int currentSpeed = this.speed;
      while (this.speed != 0) {
          this.speed /= 2;
          System.out.println("The current speed is decreasing to: " + this.speed);
      }
  }
  
  public int getSpeed() {
      return this.speed;
  }
  
  public void testVehicle() {
  
      Scanner myScanner = new Scanner(System.in);
      while (this.speed != 0) {
          System.out.println("You're driving at: " + " " + this.speed + "KM/H" + "\n\nDo you want to:"
                  + "\n(1) Slow down to " + "lower speed??" + "\n(2) Maintain current speed?"
                  + "\n(3) Hit the brakes?" + "\n(4) Accelerate even more?");
  
          int choice = myScanner.nextInt();
  
          if (choice == 1) {
              System.out.print("By how much would you like to decrease your speed? ");
              Scanner in = new Scanner(System.in);
              int dec = in.nextInt();
              this.decreaseSpeed(dec);
          } else if (choice == 2) {
              System.out.println("Maintaining current speed");
          } else if (choice == 3) {
              System.out.println("Breaking!");
              this.brake();
          }
  
          else if (choice == 4) {
              System.out.print("By how much would you like to increase your speed? (km/h)");
              Scanner in = new Scanner(System.in);
              int inc = in.nextInt();
              this.increaseSpeed(inc);
          }
  
          else {
              System.err.println("Incorrect value entererd.");
              System.exit(0);
          }
      }
  
      if (this.getSpeed() == 0)
  
      {
          System.out.println("Bilen står still");
      }
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>As you can see, the testVehicle() class along with a small separate test-program called VehicleTest runs the Vehicle class I created. I've added the Car-class to the program, and it extends vehicle as it should. The only question I have is how do I implement it into the test class?</p>
  
  <p>My current separate test-program looks like this:</p>
  
  <pre><code>public class VehicleTest {
  
  /**
   * @param args
   */
  public static void main(String[] args) {
      Vehicle bmw = new Vehicle();
      Scanner scan = new Scanner(System.in);
      System.out.println("How fast do you want to drive?");
  
      int fast = scan.nextInt();
      bmw.increaseSpeed(fast);
      bmw.testVehicle();
  }
  </code></pre>
  
  <p>}</p>