Control -  Loops Practice


Part A

Create a project (named in the usual way)  and in it a class with a main. 

Create a new class Meal representing a restaurant meal and give it instance variables for the name, the price, whether or not a drink is included, and an int for how spicy it is.

The toString should always include the name and price, add a notation if a drink is included, and have a number of stars based on how spicy it is (hint: temporary variables are your friends). So depending on the values of the instance variables it might look something like

Salad (with drink) $4.99
or
Hamburger $7.99
or
Pork Vindaloo ***** (with drink) $13.77
or
Spicy Chicken Fingers ** $9.63

Also give Meal a method totalPrice which prints the price, a 5% tax, a 15% tip, and the total.

In the main, make sure this much works.


Part B

We will be using the Scanner class to read from the user. On the class page you can look up Input Using Scanner to remind you how to do this.

Ask the user to enter the information for meals or "QUIT" for the name of the meal if they want to stop. Don't accept negative prices or spiciness values (make them keep trying each one until they give good numbers). Then print the meal they entered, and show the total price. Don't even get the rest of the info or print if they said they want to quit.

After the loop ends, print both the most expensive meal and the spiciest meal you saw (it is okay if these turn out to be the same meal.) (NOT just the price or the spiciness, but the whole meal)

hint: your life will be easier if you re-create the meal each time through the loop using new, and use a separate string for the name/"QUIT" value, then copy into the meal's name (if it isn't "QUIT") instead of just reading directly into the name of the meal itself. You can have as many temporary variables in main and other methods as makes your life easier, but remember not to add extra instance variables.