Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class TipCalculator {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String repeat = "yes";
- while (repeat.equals("yes")) {//while they want to repeat
- //1) Ask user for Total for the bill (5pts)
- System.out.print("What is your total: $");
- double paid = sc.nextDouble();
- //2) Ask for the value of the percentage they would like to tip (5pt)
- System.out.println("What percentage would you like to tip (don't include %): ");
- int tipPercen = sc.nextInt();
- //print i) amount of tip
- double tipAmount = (paid * tipPercen)/100.;
- System.out.println("Your amount to tip is $" + tipAmount);
- //print ii) the total amount of bill including the tip (bill + tip).
- paid += tipAmount;
- System.out.println("Your new total to pay is: $" + paid);
- //4) Ask for a number of people with whom to split the bill.
- System.out.print("How many people are paying: ");
- int pplPaying = sc.nextInt();
- try {
- //You will print out the amount each person needs to pay.
- double eachPerson = paid/pplPaying;
- System.out.println("Each person has to pay: $" + eachPerson);
- }catch (Exception e){
- System.out.println("Dude, come on");
- }
- //ask if they want to continue
- System.out.println("Would you like to go again? (yes or no): ");
- repeat = sc.next();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement