In this assignment, you will develop a Java console app to calculate tips. We will break the code for this assignment into two separate classes.

Class TipCalculator

This class encapsulates the tip calculation logic. It may be reused with a different user interface in a future assignment.

Data Members

The class should have the following private data members:

  • Bill amount (a double with the default value 0)
  • Tip percentage (an integer with the default value 20)
  • Party size (an integer with the default value 1)

Methods

The class should have the following methods:

  • A default constructor (optional)
  • Public getters and setters for the three data members.
  • getTotalBill() - computes and returns the total bill (bill amount plus tip).
  • getIndividualShare() - computes and returns the value of an equal share of the total bill (i.e., the total bill divided by the party size).

Class TipApp

This class encapsulates the user interface of the app.

Data Members

  • A TipCalculator object. (This could be a local variable in the calculateTips() method if you prefer.)

Methods

  • main() - creates an instance of (an object of itself!) and uses it to call
  • calculateTips() - This method will contain the logic for interacting with the user at the keyboard and displaying the output of the app. Feel free to extract parts of this logic into other methods that are called by
TipApp calculateTips()

1. Create a Scanner object to read input from the keyboard.

2. Prompt for and read the bill amount. If an invalid numeric value is entered by the user, print an error message and repeat the process until a valid value is entered. When a valid value is entered, use it to set the bill amount data member for the TipCalculator object.

3. Prompt for and read the tip percentage. If an invalid numeric value is entered by the user, print an error message and repeat the process until a valid value is entered. When a valid value is entered, use it to set the tip percentage data member for the TipCalculator object.

4. Prompt for and read the party size. If an invalid numeric value is entered by the user, print an error message and repeat the process until a valid value is entered. When a valid value is entered, use it to set the party size data member for the TipCalculator object.

5. Call the various TipCalculator methods to produce the output.

6.Ask the user whether they want to continue (enter another bill amount, tip percentage and party size) and read their response. If the response is y or Y, go back to Step 2 and repeat.

A sample run of the app might look something like this:

*** Tip Calculator ***

Enter the bill amount: 105.37
Enter your desired tip percentage (20 equals 20%): 2a
Please enter a valid tip percentage.

*** Your Bill ***

Bill Amount: $105.37
Tip Percentage: 20%
Party Size: 3

Total Bill (with Tip): $126.44
Share for Each Individual: $42.15

Another bill? (y/n): y

*** Your Bill ***
Enter the bill amount: 78.27
Enter your desired tip percentage (20 equals 20%): 23
Enter the size of your party: 2

Bill Amount: $78.27
Tip Percentage: 23%
Party Size: 2

Total Bill (with Tip): $96.27
Share for Each Individual: $48.14

Another bill? (y/n): N

Goodbye!
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.