title: how to restart a program upon meeting a condition in JAVA?
body: <p>I am new to JAVA and am writing a JAVA code that computes the cost incurred by a patient.
  If the user likes to calculate cost for another patient he enters "Y" on the prompt and the program needs to compute once more.</p>
  
  <p>How do I call the main() for the program to re-run?</p>
  
  <pre><code>/*
   * To change this license header, choose License Headers in Project Properties.
   * To change this template file, choose Tools | Templates
   * and open the template in the editor.
   */
  package demo;
  import java.util.Scanner;
  /**
   *
   * @author seshasai
   */
  public class PatientHospital {
  
      public static void main(String[] args){
        double totalCost = 0;
  
        totalCost = costCalculator();
        System.out.println("totalCosts " + totalCost);
        tryAgain();
  
  
      }
  
      public static void tryAgain(){
           String tryAgain;
        System.out.println("Do you want to calculate cost for another patient (Y/N): ");
        Scanner in = new Scanner (System.in);
        tryAgain = in.next();
        if(tryAgain.equalsIgnoreCase("Y")){
          main();
  
        }
  
      }
  
      public static double costCalculator(){
          System.out.println("Enter YES if it is a day charge, NO if it is night charge");
          Scanner i = new Scanner (System.in);
          double totalCost =0;
          String day = i.next();;
  
          if (day.equalsIgnoreCase("YES")){
               totalCost = dayCharges();
  
  
          }else if (day.equalsIgnoreCase("NO")){
              totalCost = overNightCharges();
  
          }
         return totalCost;
  
      }
      public static double overNightCharges(){
          Scanner i = new Scanner (System.in);
          System.out.println("Enter overnight, medication and labcosts");
          double onCharges = i.nextDouble();
          double medication = i.nextDouble();
          double lab = i.nextDouble();
  
          double totalFees = onCharges + medication + lab;
          return totalFees;
      }
  
      public static double dayCharges(){
          Scanner i = new Scanner (System.in);
          System.out.println("Enter medication and labcosts");
  
          double medication = i.nextDouble();
          double lab = i.nextDouble();
  
          double totalFees = medication + lab;
          return totalFees;
      }
  
  }
  </code></pre>