5A

A cruise ship line has posted the suggested tip for different quality of service levels. The tip is a percentage of the fare.

Quality of service Quality of service rating Percent of fare to tip
excellent 3 25%
good 2 20%
fair 1 10 %
poor 0 5%

Write an application called TipCalculator. It will have a main method. Ask the user for the cost of the cruise and the quality of service level. Use these prompts:

System.out.print("What was the cost of your cruise? ");
System.out.print("What was quality of service? 0 is poor and 3 is excellent: ");

The cost must be greater than 0. If not, print the error message

"The cost must be a positive number"

and terminate (do not use System.exit). Do not test the quality of service rating. Do not do any calculation

Calculate and print the tip as a percentage of the cost according to the quality of service level. Use this format for the output. (You are required to use printf . Print a $ and 2 decimal places ) Only have this in one place in your code.

"The tip should be $1057.24"

If quality of service is not a number between 0 and 3 inclusive, print the following error message:

System.out.println("Quality of service must be 0, 1, 2, or 3");

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

final double EXCELLENT_TIP = .25;
final int EXCELLENT_SERVICE = 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 cost and the rating and print those out on one line with a space between them like this:
1025.45 2

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

JavaBuilding

ShoppingCart

output

Emblem

For the draft, add the error checking for Emblem

 

5B draft:
5B final:

5C

In this assignment, you will write a simple SpanishTranslator class which will translate a few Spanish words to English. There is no starter class

Provide a constructor for the class that takes a String as a parameter.

Provide these methods:

Here are the only words our translator knows so far

Spanish English
estudiante student
aprender to learn
entender to understand
verde green
any other word null

If the first three letters of the Spanish word are "el " or "la " then ignore those letters. This is a definite article meaning "the"

Here is pseudocode for getEnglish

if the first three letters of the word are "el "
        use substring to get the tail of the word without the first three letters else 
if the first three letters of the word are "la "
        use substring to get the tail of the word without the first three letters 
Now use if / else if / else to compare your word with each word in the table.
if you find a match, 
        return value to the English translation
otherwise return null          

Provide all the Javadoc.

For the draft, provide the instance variable(s), the constructor which initializes the instance variable(s), the setSpanish and getSpanish methods. Provide Javadoc for those methods, the constructor, and the class.

My apologies to you Spanish speakers. Please ignore any errors in the translation and just follow the directions.

5C draft:
5C final: