a boat sails 4km on a bearing of 38degree and then 5km on a bearing of 67degree

You sail on a heading. You take a bearing on something like a lighthouse or another boat.

Anyway
distance East (x) = 4 sin 38 + 5 sin 67
= 2.46 + 4.60
= 7.06
(note the compass is clockwise from Y axis, not counterclockwise from X axis as in a math text )
distance North (y) = 4 cos 38 + 5 cos 67
3.15 + 1.95
= 5.10
distance traveled = sqrt( 7.06^2 + 5.10^2)
tangent of bearing of finish point from start = 7.06/5.10
so bearing = 54 degrees clockwise from North