Skip to content

Instantly share code, notes, and snippets.

@viveknarang
Created January 26, 2018 22:21
Show Gist options
  • Save viveknarang/07b398e5893c61b9ce8f5664dd3e7f68 to your computer and use it in GitHub Desktop.
Save viveknarang/07b398e5893c61b9ce8f5664dd3e7f68 to your computer and use it in GitHub Desktop.
import java.util.Scanner;
public class BillCalc {
public static void main(String[] args) {
//Declare variables to be used (billAmount, nosOfDiners)
int billAmount = 0;
int nosOfDiners = 0;
Scanner scnr = new Scanner(System.in);
System.out.println("Enter bill amount:");
billAmount = scnr.nextInt();
System.out.println("Amount due from each diner based on tip percentage:");
Double tip15per = billAmount*.15;
Double tip18per = billAmount*.18;
Double tip20per = billAmount*.20;
Double total15per = billAmount + tip15per;
Double total18per = billAmount + tip18per;
Double total20per = billAmount + tip20per;
System.out.println("15 % :" + tip15per + " | Total bill: " + total15per);
System.out.println("18 % :" + tip18per + " | Total bill: " + total18per);
System.out.println("20 % :" + tip20per + " | Total bill: " + total20per);
System.out.println("Amount due each diner based on tip percentage");
Double dinerDue15 = total15per/nosOfDiners;
Double dinerDue18 = total18per/nosOfDiners;
Double dinerDue20 = total20per/nosOfDiners;
System.out.println("Tip Amount 15% :" + dinerDue15 +"due");
System.out.println("Tip Amount 18% :" + dinerDue18 +"due");
System.out.println("Tip Amount 20% :" + dinerDue20 +"due");
scnr.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment