Question

Write a Java program called Solution.java that will calculate the tip to leave at a restaurant. Your program must ask the user for the amount of the bill (this could contain decimals), and the percent they want to tip. The user will enter the percent they want to tip as an integer, e.g. 15 for 15%. Then your program should calculate and display the tip amount and the total bill after including the tip. To calculate the tip amount, multiply the bill amount times the percent divided by 100 (be careful of integer division).

Make sure to use the following:
- Comments explaining the main parts of the code (Getting input, calculating results, etc)
- Descriptive variable names with appropriate types
- Appropriate indentation between braces
- The NumberFormat class to format the output to be display as currency

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

import java.text.NumberFormat;
import java.util.Scanner;

class Solution
{
   
    public static void main( String[] args )
    {
       // Declear double bill and int tipPercent to read from Scanner input
       double bill;
       int tipPercent;
      
       // Creat a Scanner instance in.
       Scanner in = new Scanner(System.in);
       // Message to prompt a user to input amount of bill and tip separated by a space
       System.out.println( "Enter the amount of the bill and the percent you want to tip separated by a space: " );
       bill = in.nextDouble(); // assign the bill supplied by the user to bill
       tipPercent = in.nextInt(); // assign the tip % supplied by the user to tipPercent...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Assisting Tutor

Related Homework Solutions

The Problem Solver in Java
Homework Solution
$30.00
Java
Programming
Codes
Algorithms
Lists
Tasks
Computer Science
Conversions
Celsius
Fahrenheit
Odd Numbers
Even Numbers
User Choices
Input
Output
Statements
Strings
Mathematical Equations
Variables
Java Programming Assignment
Homework Solution
$30.00
Java Programming
Variables
ToString Method
Equals Method
Overload
Computer Science
Pyramid Using Asterisks in Java
Homework Solution
$30.00
Java
Programming
Codes
Algorithms
Computer Science
Statements
Variables
Loops
Input
Output
Integers
Strings
Asterisks
Symbols
Pyramid
Rows
Odd Numbers
Java Programming Assignment
Homework Solution
$40.00
Java Programming
Computer Science
Arrays
Dynamic Allocation
ArrayList
Constructor
Arrays in Programming Language Java
Homework Solution
$20.00
Java
Programming
Computer Science
Arrays
Integers
Random Numbers
Methods
Functions
Even Elements
Odd Elements
Prime Numbers
Minimum Values
Maximum Values
Average Values
Loops
Conditions
Statements
Get help from a qualified tutor
Live Chats