Tip Calculator

/** * Charlotte Weisman * B Computer Science * September 19, 2017 * * Tip Calculator */ import java.util.*; public class tipCalculator { public static void main(String args[]){ Scanner sc = new Scanner(System.in); boolean keepGoing = true; while(keepGoing) { //allow program to run again //input amounts System.out.println("How much is the check? (without $ symbol)"); double bill = sc.nextDouble(); System.out.println("What percentage would you like to tip? (without % symbol)"); double perc = sc.nextDouble() / 100; //do math and print results double tip = (bill * perc); double total = (bill + tip); int newTip = (int)(tip * 100); //convert to int so no long decimals int newTotal= (int)(total * 100); System.out.println("Tip=" + (double)newTip/100); System.out.println("Total=" + (double) newTotal/100); System.out.println("How many people are splitting the bill?"); //divide by number of people int split = sc.nextInt(); double each = total / (double)split; System.out.println("Your total is " + each + " each."); System.out.println("Press 1 to calculate another check. Press any other number to quit."); int cont = sc.nextInt(); if(cont !=1){ //allow program to quit keepGoing = false; } } System.out.println("End of program"); } }

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.