Solving a word problem using the law of cosines