title: Passing by value in menu driven Java program
body: <p>I am trying to write a simple program that utilizes passing by value to calculate total revenue for all three ticket classes when user selects option <strong>4</strong>. I want method income_Generated to run all first three methods again so I can pass the revenues calculated from each ticket class to calculate total rev. Is there another way to accomplish the same objective? or can someone show me how this can be done?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import java.util.Scanner; 
  public class Functions_Menu_Driven 
  { 
      public static void main(String[]args) 
      { 
      //call the method menu() 
        menu(); 
      }//end main 
      public static void menu()
      {
        int selection;
        double revA,revB,revC;
        Scanner keyboard=new Scanner(System.in);
        System.out.println("***************************Menu*****************************");
        System.out.println("**Calculate revenue from Class A ticket sales [1]**");
        System.out.println("**Calculate revenue from Class B ticket sales [2]**");
        System.out.println("**Calculate revenue from Class C ticket sales [3]**");
        System.out.println("**Revenue from Class A, B and C ticket sales  [4]**");
        System.out.println("**End                                         [5]**");
        //allow user to select a choice
        selection=keyboard.nextInt();
        if(selection==1)
       a();
       else if(selection==2)
       b();
       else if(selection==3)
       c();
       else if(selection==4)
       income_Generated();
       else
       exit();
       keyboard.close();
  }
       public static void a()
  {
       double rA, nticketsA;
       Scanner keyboard=new Scanner(System.in);
       do {
         System.out.println("How many Class A tickets were sold?  ");
         while(!keyboard.hasNextDouble())
         { System.out.println("That's not a number!");
           keyboard.next();
         } 
         nticketsA=keyboard.nextDouble();
         }while(nticketsA &lt;=0);
         System.out.println("Thank you! Got"+nticketsA);
         //calculate rev for class A tickets
         rA=15*nticketsA;
         System.out.printf("Revenue:%5.2f ",rA);
         System.out.println("");
         income_Generated(rA);
         keyboard.close();
         //end module
       }
       public static void b()
       {
         double rB, nticketsB, costB;
         Scanner keyboard=new Scanner(System.in);
         do{
           System.out.println("How many Class B tickets were sold? ");
           while(!keyboard.hasNextDouble())
           { System.out.println("That's not a number!");
             keyboard.next();
           }
           nticketsB=keyboard.nextDouble();
         }while(nticketsB&lt;=0);
         System.out.println("Thank you! Got"+nticketsB);
         //prompt user input for cost of 1 ticket
         do{
           System.out.println("What is the cost of 1 ticket? ");
           while(!keyboard.hasNextDouble())
           { System.out.println("That's not a number!");
             keyboard.next();
           }
           costB=keyboard.nextDouble();
         }while(costB&lt;=0);
         System.out.println("Thank you! Got"+costB);
         //calculate rev for class B tickets
         rB=costB*nticketsB;
         System.out.printf("Revenue:%5.2f ",rB);
         System.out.println("");
         income_Generated(rB);
         keyboard.close();
         //end module
       }
       public static void c()
       {
         double rC, nticketsC, costC;
         Scanner keyboard=new Scanner(System.in);
         do{
           System.out.println("How many Class C tickets were sold? ");
           while(!keyboard.hasNextDouble())
           { System.out.println("That's not a number!");
             keyboard.next();
           }
           nticketsC=keyboard.nextDouble();
         }while(nticketsC&lt;=0);
         System.out.println("Thank you! Got"+nticketsC);
         //prompt user input for cost of 1 ticket
         do{
           System.out.println("What is the cost of 1 ticket? ");
           while(!keyboard.hasNextDouble())
           { System.out.println("That's not a number!");
             keyboard.next();
           }
           costC=keyboard.nextDouble();
         }while(costC&lt;=0);
         System.out.println("Thank you! Got"+costC);
         //calculate rev for class B tickets
         rC=costC*nticketsC;
         System.out.printf("Revenue:%5.2f ",rC);
         System.out.println("");
         income_Generated(rC);
         keyboard.close();
         //end module
       }
       public static void income_Generated(revA,revB,revC)
       {
         a();
         b();
         c();
         Scanner keyboard=new Scanner(System.in);
         //calculate total rev
         total=revA+revB+revC;
         System.out.printf("Total revenue from all ticket classes:%5.2f ",total);
         System.out.println("");
         keyboard.close();
  }
       public static void exit()
       {
         System.out.println("Goodbye!");
       }
  }</code></pre>
  </div>
  </div>
  </p>