title: Stop method from running twice
body: <p>In the method <code>askCarType()</code> and <code>askSolarPanel()</code> the inputdialog both run two times, once in their own method and once more in the final method <code>PrintOptions()</code>.</p>
  
  <p>I need them to only run once, and that is in the final method <code>PrintOptions()</code>.</p>
  
  <p>How can I do that?</p>
  
  <pre><code>import javax.swing.*;
  
  public class short7 {
  
      /**
       * @param args
       */
      public static void main(String[] args) {
          // TODO Auto-generated method stub
  
          PrintOptions();
  
      }// ends main
  
      public static String askCarType() {
          String typeOfCar;
          typeOfCar = JOptionPane.showInputDialog("Electric or Hybrid?");
          if (!typeOfCar.equals("Electric")
                  &amp;&amp; (!typeOfCar.equals("electric") &amp;&amp; (!typeOfCar
                          .equals("Hybrid") &amp;&amp; (!typeOfCar.equals("hybrid"))))) {
              JOptionPane
                      .showMessageDialog(null,
                              "You have to choose either an Electric or Hybrid type of car.");
              typeOfCar = JOptionPane.showInputDialog("Electric or Hybrid?");
          }
          return typeOfCar;
      }// ends askCarType
  
      public static String askSolarPanel() {
          String wantSolarPanel;
          wantSolarPanel = JOptionPane
                  .showInputDialog("Do you want a Solar Panel?");
          if (!wantSolarPanel.equals("Yes")
                  &amp;&amp; (!wantSolarPanel.equals("yes") &amp;&amp; (!wantSolarPanel
                          .equals("No") &amp;&amp; (!wantSolarPanel.equals("no"))))) {
              JOptionPane.showMessageDialog(null,
                      "You have to enter either Yes or No");
              wantSolarPanel = JOptionPane
                      .showInputDialog("Do you want a Solar Panel?");
          }
          return wantSolarPanel;
      }// ends askSolarPanel
  
      public static int calculateDiscount() {
          String typeOfCarSelected = askCarType();
          String SolarPanelSelected = askSolarPanel();
          int Discount = 0;
          if ((typeOfCarSelected.equals("Electric") || typeOfCarSelected
                  .equals("electric"))
                  &amp;&amp; ((SolarPanelSelected.equals("Yes") || SolarPanelSelected
                          .equals("yes")))) {
              Discount = 500;
          } else {
              Discount = 0;
          }
          return Discount;
      }// ends calculateDiscount
  
      public static int CalculateCost() {
          String typeOfCarCost = askCarType();
          String SolarPanelCost = askSolarPanel();
          final int basicPrice = 20000;
          final int ElectricModel = 2000;
          final int SolarPanel = 5000;
          final int Discount = calculateDiscount();
          int total = 0;
  
          if ((typeOfCarCost.equals("Electric") || typeOfCarCost
                  .equals("electric"))
                  &amp;&amp; ((SolarPanelCost.equals("No") || SolarPanelCost.equals("no")))) {
              total = basicPrice + ElectricModel;
              System.out.println("Basic Price:" + basicPrice);
              System.out.println("Electric Model:" + ElectricModel);
              System.out.println("Total:" + total);
  
          } else if ((typeOfCarCost.equals("Electric") || typeOfCarCost
                  .equals("electric"))
                  &amp;&amp; ((SolarPanelCost.equals("Yes") || SolarPanelCost
                          .equals("yes")))) {
              total = basicPrice + ElectricModel + SolarPanel - Discount;
              System.out.println("Basic Price:" + basicPrice);
              System.out.println("Electric Model:" + ElectricModel);
              System.out.println("Solar Panel:" + SolarPanel);
              System.out.println("Discount:" + Discount);
              System.out.println("Total:" + total);
          } else {
              total += basicPrice;
              System.out.println("Basic Price:" + basicPrice);
              System.out.println("Total:" + total);
          }
          return total;
      }// ends CalculateCost
  
      public static void PrintOptions() {
          CalculateCost();
      }// ends PrintOptions
  
  }// ends class short7
  </code></pre>