Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class TipCalculator {
  4.  
  5. public static void main(String[] args) {
  6. Scanner sc = new Scanner(System.in);
  7. String repeat = "yes";
  8.  
  9. while (repeat.equals("yes")) {//while they want to repeat
  10. //1) Ask user for Total for the bill (5pts)
  11. System.out.print("What is your total: $");
  12. double paid = sc.nextDouble();
  13.  
  14. //2) Ask for the value of the percentage they would like to tip (5pt)
  15. System.out.println("What percentage would you like to tip (don't include %): ");
  16. int tipPercen = sc.nextInt();
  17.  
  18. //print i) amount of tip
  19. double tipAmount = (paid * tipPercen)/100.;
  20. System.out.println("Your amount to tip is $" + tipAmount);
  21.  
  22. //print ii) the total amount of bill including the tip (bill + tip).
  23. paid += tipAmount;
  24. System.out.println("Your new total to pay is: $" + paid);
  25.  
  26. //4) Ask for a number of people with whom to split the bill.
  27. System.out.print("How many people are paying: ");
  28. int pplPaying = sc.nextInt();
  29.  
  30. try {
  31. //You will print out the amount each person needs to pay.
  32. double eachPerson = paid/pplPaying;
  33. System.out.println("Each person has to pay: $" + eachPerson);
  34. }catch (Exception e){
  35. System.out.println("Dude, come on");
  36. }
  37.  
  38.  
  39. //ask if they want to continue
  40. System.out.println("Would you like to go again? (yes or no): ");
  41. repeat = sc.next();
  42. }
  43.  
  44.  
  45. }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement