I fixed the error in the getCost() method. Now it functions perfectly.