All pastes #332554 Raw Edit

Anonymous

public text v1 · immutable
#332554 ·published 2007-01-30 02:16 UTC
rendered paste body
Rewrite the Lunch class from Case One, Chapter 1, to incorporate the object-oriented
principles you have learned in this chapter. Here are some guidelines:
1. The variables will now be private data members of the Lunch class.
2. A constructor will initialize the amount and cost of each item for a lunch. It will also
retrieve the budget amount from the user and set the budget variable. The String
variable that holds the user input should be a local variable in the constructor.
3. Additional methods will be responsible for calculating and displaying the total cost.
Return a value from the calculation method that represents the total price of the
items. The display method will call the calculation method and display the total. It
will also display whether the total exceeded the budget.
4. Test the Lunch class with another class named MakeLunch.







Chap 3 Case Project Two
Add get and set methods to the Lunch class of Case One to retrieve the item amounts, total,
and budget, and to modify the item amounts. The set methods will use parameters to
specify the new values.
Modify the MakeLunch class to display all information using the get and set methods. The
class will first display the costs of each item by using the get methods. It will then use the
set methods to specify the values for the amounts. After displaying the total, modify the
costs of each item and repeat the process.