CSCI 470/502 Assignment 3 – Tip Calculator Console Program solution

$24.99

Category:

Description

5/5 - (2 votes)

In this assignment, you will write a Java console program to calculate tips. We’ll break the code for this
assignment into two separate classes.
Class
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.
• – computes and returns the total bill (bill amount plus tip).
• – computes and returns the value of an equal share of the total bill (i.e., the
total bill divided by the party size).
Class
This class encapsulates the user interface of the program.
Data Members
• A object. (This could be a local variable in the method if you
prefer.)
Methods
• – creates an instance of (an object of itself!) and uses it to call .
• – This method will contain the logic for interacting with the user at the keyboard
and displaying the output of the program. Feel free to extract parts of this logic into other methods that
are called by .
1. Create a object to read input from the keyboard.
CSCI 470/502 Assignment 1 – Tip Calculator Console Program Page 2 of 3
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 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 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 object.
5. Call the various 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.
Notes
• To make grading by the TAs easier, remove all package statements in the .java files that you submit.
• Invalid input should include values that are not numeric (which will result in a
when Java attempts to convert them to a number) as well as numeric values
that should not be possible.
For example, it would be impossible to have a negative bill amount or a party size of 0. However, a tip
percentage of 0 should certainly be possible.
• Both upper- and lower-case letters should be allowed in the user’s response to the
“Another bill? (y/n): ” prompt.
Submit your two .java files on Blackboard. Do NOT zip your files for submission.
Sample Output
A sample run of the program might look something like this:
CSCI 470/502 Assignment 1 – Tip Calculator Console Program Page 3 of 3
(Sample output continues on next page.)