public void Update() {

        //the following all increase the speed as a key is pressed
        // Calculating speed for moving up 
        if (Canvas.keyboardKeyState(KeyEvent.VK_W)) {
            if (speedY >= TOP_SPEED * - 0.5) {
                speedY -= speedAccelerating;
            } else {
                speedY += speedStopping;
            }
        }

        // Calculating speed for moving down.
        if (Canvas.keyboardKeyState(KeyEvent.VK_S)) {
            if (speedY <= TOP_SPEED * 0.5) {
                speedY += speedAccelerating;
            } else {
                speedY -= speedStopping;
            }
        }
            // Calculating speed for moving or stopping to the left.
        if (Canvas.keyboardKeyState(KeyEvent.VK_A)) {
            speedX -= speedAccelerating;
        } else if (speedX < 0) {
            speedX += speedStopping;
        }

        
        // Calculating speed for moving or stopping to the right.
        if (Canvas.keyboardKeyState(KeyEvent.VK_D)) {
            speedX += speedAccelerating;
        } //if no keys are being press slow the car
        else if (speedX > 0) {
            speedX -= speedStopping;
        }

        // Moves the car.
        x += speedX;
        y += speedY;
    }