/**
* Calculates the total amount of a bill (including tip) each person needs to pay based on several factors including price of bill, percentage of tip, and amount of people.
*
* @author Sameer
* @version 1.0
*/
import java.util.*;
public class TIpCalculator
{
public static void main (String args[]) {
while (true) {
//Initializes first scanner object
Scanner scan = new Scanner(System.in);
//Determines the value of the bill by itself
System.out.println("What was the value of the bill? ");
double bill = scan.nextDouble();
//Determines the percentage of the bill the user would like to tip
System.out.println("What percentage would you like to tip? ");
double percentTip = scan.nextDouble();
//Determines and displays the amount of the tip and the total cost of the bill when including the tip
double amtTip = bill * (percentTip / 100.0);
double total = bill + amtTip;
System.out.println("The amount of the tip comes out to be: $" + amtTip);
System.out.println("The total amount paid comes out to be: $" + total);
//Determines the amount of people in the party who are involved in splitting the bill
System.out.println("How many people are splitting the bill? ");
double numOfPeople = scan.nextDouble();
//Determines the amount each person in the party needs to pay
double amtFromPeople = total / numOfPeople;
System.out.println("Each person must pay $" + amtFromPeople);
//Asks the user if he/she would like to run the program again
Scanner scan2 = new Scanner(System.in);
System.out.println("Would you like to make another calculation? Press Y if so.");
String answer = scan2.nextLine();
if (!answer.equals("Y")) {
//If the user would not like to run the program again, stop the program
break;
}
} //End while loop
} //End main method
} //End TIpCalculator class
Calculates the total amount of a bill (including tip) each person needs to pay based on several factors including price of bill, percentage of tip, and amount of people.
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.