Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class TipCalculator {
- public static void main(String[] args) {
- // declare variables
- boolean calculate = true;
- //begin program
- while(calculate==true){
- Scanner input1 = new Scanner(System.in);
- System.out.println("Please enter value of bill");
- double bill=0;
- boolean allGood = true;
- try
- {
- bill = input1.nextDouble();
- }
- catch(Exception e)
- {
- allGood = false;
- // System.out.println("Please enter a valid bill amount in dollars and cents.");
- }
- // double roundedBill = (((int)(100 * bill + .05) )/100); // rounds to hundredths place
- if (allGood == true){
- Scanner input2 = new Scanner(System.in);
- System.out.println("Please enter the percentage you would like to tip");
- double tip = input2.nextDouble();
- double tipAmount = bill * tip;
- double totalAmount = bill * (tip + 1);
- double roundedTip = (((int)(100 * tipAmount) )/100.0);
- double roundedTotal = (((int)(100 * totalAmount + .05) )/100.0);
- System.out.println("Your tip amount is " + roundedTip + " and your total bill is " + roundedTotal);
- Scanner input3 = new Scanner(System.in);
- System.out.println("How many people are you splitting the bill between?");
- double numPeople = input3.nextDouble();
- double amountPerPerson = totalAmount / numPeople;
- double roundedAmtPP = (int)(100 * amountPerPerson + .05) / 100.0;
- System.out.println("The amount each person should pay is " + roundedAmtPP);
- System.out.print("Would you like to calculate another tip? Enter 1 for yes, enter 2 to leave.");
- Scanner input4 = new Scanner(System.in);
- int calculateAgain = input4.nextInt();
- if(calculateAgain==1){
- calculate = true;
- }
- if(calculateAgain==2){
- calculate = false;
- }
- }//end of all good
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement