added totalCost function to Purchase object