5A

Your rich uncle is taking you to dinner is a fine restaurant. He knows he needs to add a tip to the cost of the food and drink on the bill. And that the tip is calculated as a percentage of the fare with the percentage being determined by the quality of the service.

Here is a table of the percentage tip to give for different service levels.

Quality of service Quality of service rating Percent of bill to tip
excellent 4 30%
good 3 25%
fair 2 10 %
poor 1 5%

Your uncle asks you to write an application to do the calculations for him

Write an application called RestaurantAssistant. It will have a main method. The application asks the user for the amount of the bill and the quality of service using Scanner. Use these prompts:

System.out.print("What is the amount of the bill? ");
System.out.print("How was quality of service? 1 is poor and 4 is excellent: ");

Do the following error checking:

(Note for advanced students: do not use System.exit to terminate the program).

If the amount of the bill and the service rating are both valid: Calculate the tip as a percentage of the bill according to the quality of service level. Print the tip and print the total amount to pay (the bill + the tip) Only do this printing one place in your code.

Use printf. Print the amounts with a $ and 2 decimal places .

Format for the output like this.

The tip should be $62.25
Please pay $312.50

Use local constants for the tip percentages and for the quality of service ratings like this

final int EXCELLENT_SERVICE = 4;
final double EXCELLENT_TIP = .3;

I recommend you copy/paste the prompts and the messages so you will get exactly what Codecheck expects.

No Javadoc since you are only submitting an application with a main method.

For the draft, ask for the amount of the bill and print it. If the amount is less than or equal to 0, print the error message given above.

5A draft:
5A final:

5B

We do not want users of our classes to be able to set invalid values for instance variables. Now that you know how to use if statements, you are going to add error checking to a a few classes from earlier homeworks. You can copy correct solutions from Canvas Modules.

You should not print error messages from constructors or methods of object. In the real world, you might throw an exception when the parameter is invalid, but we have not covered exceptions yet. We will just be sure the data in our objects are valid. Follow the directions below to add error checking to each class.

Use proper if structure. Do not do unnecessary tests . Do not have empty if or else blocks

PaintJob (hw 4)

PiggyBank (hw 3)

RobotFriend (hw 3)

If you do not have a correct version of one of these classes, you can get it from the posted solutions.

For the draft, make the changes to PaintJob

5B draft: (Changed Feb 22, 2017)
5B final:

5C

Now let's conjugate some Spanish verbs. We will only look at first person preterite tense. All Spanish verbs end in ar, er, or ir. Most verbs are regular. A few irregular verbs are given in the table below

English Spanish Present Tense Spanish Preterite Tense First Person
to take sacar saqué
to read leer leĆ­
to be ser fui
     

To form the first person preterite tense of regular verbs:

Write a class SpanishVerb. Its constructor takes a verb in present tense as a parameter (a String). If the parameter is not a proper verb (does not end in ar, er, or ir), set the instance variable to ser

Provide methods

Provide Javadoc

You do not need to know any Spanish to do this assignment. And Spanish speakers, please ignore any errors on my part. All you need to do is follow the directions.

For the draft, provide instance variable(s), the constructor, the getVerb method, and the setVerb method. Code getFirstPersonPreteriteTense as a stub. Provide Javadoc for the class, the constructor and all methods.

5C draft:
5C final: