In a pseudocode program,,,write a program that computes and displays a 15b percent tip when the price of a meal input by the user.(Hint: the tip is computed by multiplying the price of the meal by 0.15 ) You will need the following Variables: MealPrice (a Float) Tip (a Float)

Expert Answers

An illustration of the letter 'A' in a speech bubbles

To accomplish the completion of this program, you would only need a single function to determine the tip total. The function would look something like this:

public float getTip(float mealPrice) {

        return mealPrice * 0.15;


Just as a reminder, since we have a constant (0.15), it is good coding practice to have a final variable at the top (above your main function) that can be in place instead of a hard coded value. A final variable at the top makes the code look much more readable. The variable can be at the top, like so:

private static final float TIP_PERCENTAGE = 0.15f;

Then the function would look like this:

public float getTip(float mealPrice) {

       return mealPrice * TIP_PERCENTAGE;


Finally, this is how you would call the function and display the calculation:

public static void main(String[] args) {

      float mealPrice = 5.00f;

      float calculation = getTip(mealPrice);

      System.out.println("Price: " + calculation);


Approved by eNotes Editorial Team

Posted on

Soaring plane image

We’ll help your grades soar

Start your 48-hour free trial and unlock all the summaries, Q&A, and analyses you need to get better grades now.

  • 30,000+ book summaries
  • 20% study tools discount
  • Ad-free content
  • PDF downloads
  • 300,000+ answers
  • 5-star customer support
Start your 48-Hour Free Trial