Tip Calculator

/** * Calculate tip amount * * @author Sean Appaneal * * @version v1.0 * */ import java.util.*; public class tipCalculator { public static void main(String[] args) { boolean keepGoing = true; while(keepGoing){ Scanner sc = new Scanner(System.in); //get bill System.out.println("Please enter the price"); double price = sc.nextDouble(); //get tip % + convert System.out.println("Please enter the percent you would like to tip"); double tip = sc.nextDouble(); double tipConv = price * (tip /100); System.out.println("Your total tip is: " + tipConv); //combine tip with price and print double total = tipConv + price; System.out.println("Your combined bill and tip is: " + total ); //divide bill between multiple people System.out.println("How many people would you like to divide the tip between?"); double ppl = sc.nextDouble(); double finTip = tipConv/ppl; System.out.println("Each person should pay: " + finTip); //loop through program System.out.println("Press 1 to continue, press 2 to stop" ); int go = sc.nextInt(); if(go != 1) keepGoing = false; }//end of while }//end of main }//end of class

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.