Here is a module that simulates the length of the longest piece in problem 3(b).

longest[]:=Module[{u},
u=RandomVariate[UniformDistribution[{0,1}]];
Print["u: ",u];
Print["longest: ", Max[u,1-u]];
Return[Max[u,1-u]]
]

Try it out:

longest[]

Now run 1000 simulations and compute the average:

Mean[Table[longest[],1000]]