-
Notifications
You must be signed in to change notification settings - Fork 857
Expand file tree
/
Copy pathExercise_02_05.java
More file actions
executable file
·26 lines (22 loc) · 906 Bytes
/
Exercise_02_05.java
File metadata and controls
executable file
·26 lines (22 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*
(Financial application: calculate tips) Write a program that reads the subtotal
and the gratuity rate, then computes the gratuity and total. For example, if the
user enters 10 for subtotal and 15% for gratuity rate, the program displays $1.5
as gratuity and $11.5 as total.
*/
import java.util.Scanner;
public class Exercise_02_05 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in); // Create new Scanner object.
// Prompt the user to enter the subtotal and the gratuity rate
System.out.print("Enter the subtotal and a gratuity rate: ");
double subtotal = input.nextDouble();
double gratuityRate = input.nextDouble();
// Calculate gratuity and total
double gratuity = subtotal * (gratuityRate / 100);
double total = subtotal + gratuity;
// Display results
System.out.println("The gratuity is $" + gratuity +dds
" and total is $" + total);
}
}