TipCalc

//Alex Lee //9/17/17 import java.text.DecimalFormat; import java.util.Scanner; public class TipCalc {//beginning of class public static void main(String[] args) {//beginning of static Scanner sc = new Scanner(System.in);//scans boolean keepGoing = true;//loop while(keepGoing){ //beginning of while DecimalFormat format = new DecimalFormat("0.00");//decimals System.out.println("\nYou have just finished your meal at the Edwin's Pasta Parlor."); System.out.println("\nHow much did you pay for your meal? $: "); //String in = ""; //in = sc.nextLine(); double bill = sc.nextDouble();//scans //try { //} catch (Exception InputMismatchException) { // } System.out.println("\nYou payed $" + bill); System.out.println("\nWhat percentage of the bill would you like to tip to Edwin?"); //try { // } catch (Exception %) { // }} double percentage = sc.nextInt();//percent of bill double tip = bill * percentage/100;//tip double total = tip + bill;//total System.out.println("\nYou tipped Edwin $" + format.format(tip)); System.out.println("\nYour total payment is $" + format.format(total)); System.out.println("\nTo have another yummy meal press 1, any other number to exit"); int cont = sc.nextInt();//scans if(cont != 1) //! means not = to 1 keepGoing = false; }//end of while }//end of static }//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.