Question: This activity is based on Exercises 2 . 5 4 to 2 . 5 6 , with some modifications. Our example concerns a class called

This activity is based on Exercises 2.54 to 2.56, with some modifications.
Our example concerns a class called Budget, and an incomplete version of this class is provided below. This class provides methods relating to costs of items and whether we can afford them.
Some methods have empty bodies that need to be completed as follows:
Complete the method called setTotalCost, which finds the product of the parameters called unitPrice and quantity and stores the result in the field called totalCost.
Complete the method called setMeanCost. The method divides the parameter totalCost by the parameter units, and stores the result in the field meanCost.
Complete the method called printAffordability. The method uses an if-statement to compare the value of the parameter price with the field called budget. If price is greater than budget then the method prints
Too expensive
otherwise it prints
Within budget

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!