CLASS ZCL_OO_TUTORIAL_5 DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.

    TYPES:
      BEGIN OF COST,
        PRICE    TYPE /DMO/FLIGHT_PRICE,
        CURRENCY TYPE /DMO/CURRENCY_CODE,
      END OF COST .

    "! <p class="shorttext synchronized" lang="en">CONSTRUCTOR</p>
    METHODS CONSTRUCTOR
      IMPORTING
        !CARRIER_ID    TYPE /DMO/CARRIER_ID
        !CONNECTION_ID TYPE /DMO/CONNECTION_ID
        !FLIGHT_DATE   TYPE /DMO/FLIGHT_DATE
      RAISING  ZCX_OO_TUTORIAL.

    "! <p class="shorttext synchronized" lang="en">Get Booking Details</p>
    METHODS GET_FLIGHT_DETAILS
      RETURNING VALUE(FLIGHT) TYPE /DMO/FLIGHT.

    "! <p class="shorttext synchronized" lang="en">Calculate Flight Price</p>
    METHODS CALCULATE_FLIGHT_PRICE
      RETURNING
        VALUE(PRICE) TYPE COST.

  PROTECTED SECTION.
  PRIVATE SECTION.
    "! <p class="shorttext synchronized" lang="en">Flight</p>
    DATA FLIGHT TYPE /DMO/FLIGHT.
ENDCLASS.



CLASS ZCL_OO_TUTORIAL_5 IMPLEMENTATION.


  METHOD CALCULATE_FLIGHT_PRICE.

    PRICE-PRICE = ME->FLIGHT-PRICE.
    PRICE-CURRENCY = ME->FLIGHT-CURRENCY_CODE.

    CASE ME->FLIGHT-PLANE_TYPE_ID.
      WHEN '747-400'.
        PRICE-PRICE =  PRICE-PRICE + 40.
      WHEN 'A310-300'.
        PRICE-PRICE =  PRICE-PRICE + 25.
      WHEN OTHERS.
        PRICE-PRICE =  PRICE-PRICE + 10.
    ENDCASE.
  ENDMETHOD.


  METHOD CONSTRUCTOR.
    SELECT SINGLE * FROM /DMO/FLIGHT
      WHERE CARRIER_ID = @CARRIER_ID
        AND CONNECTION_ID = @CONNECTION_ID
        AND FLIGHT_DATE = @FLIGHT_DATE
       INTO @FLIGHT.
    IF SY-SUBRC NE 0.
      RAISE EXCEPTION NEW ZCX_OO_TUTORIAL(
        TEXTID   = ZCX_OO_TUTORIAL=>FLIGHT_NOT_FOUND
        CARRID   = CARRIER_ID ).
    ENDIF.
  ENDMETHOD.


  METHOD GET_FLIGHT_DETAILS.
    FLIGHT = ME->FLIGHT.
  ENDMETHOD.
ENDCLASS.
