Skip to main content

public static void

public static void calculateTips()
{
//Varibles
int tipPercentage = 0;
int partySize = 0;
double billAmount = 0.0;
//Variable to loop through try catch blocks
int x = 0;

String yesOrNo;

 boolean choice;
//Decimal Format
DecimalFormat dollar = new DecimalFormat("$###,##0.00");

//Declare object
TipCalculator bill;

//Create Scanner object
Scanner userInput = new Scanner(System.in);

do
{
  //Fill values for tip calculator from user
  System.out.println("Enter the bill amount: ");

  try
  {

     billAmount = userInput.nextDouble();

     if(billAmount < 0)

      throw new Exception("Bill amount can not be negative. Please try again.");



     System.out.println("Enter your desired tip percentage (20 equals 20%): ");
     tipPercentage = userInput.nextInt();

     if(tipPercentage < 0)
       throw new Exception("Tip percentage can not be negative. Please try again.");

     System.out.println("Enter the size of your party: ");
     partySize = userInput.nextInt();

      if(partySize < 0)
        throw new Exception("Party Size can not be negative. Please try again.");


  }
  catch(Exception e)
  {
   System.out.println("Invalid Input. Please try again." + "n");
   calculateTips();
  }