I am building a program that tracks the Total Sales for employees
Here is my code, it compiles fine but how do I take a variable from a method and pass it to another method?
Expand|Select|Wrap|Line Numbers
- public class main_Menu
- {
- public static void main (String[] args)
- {
- main_menu();
- }
- public static void main_menu ()
- {
- System.out.println (" ");
- System.out.println ("Please Choose One of the Following (chose a #)");
- System.out.println ("1. Enter Data for employee");
- System.out.println ("2. Show total sales");
- System.out.println ("3. Show average sale");
- System.out.println ("4. Show max and min sale");
- System.out.println ("5. Check for sales larger then");
- int user_Choice = 0;
- try
- {
- BufferedReader in = new BufferedReader( new InputStreamReader(System.in));
- user_Choice = Integer.parseInt( in.readLine() );
- }
- catch ( Exception e )
- {
- e.printStackTrace();
- }
- if (user_Choice == 1){
- enter_Data();
- }
- else if (user_Choice == 2){
- total_Sales();
- }
- else if (user_Choice == 3){
- average_Sales();
- }
- else if (user_Choice == 4){
- max_min_sale ();
- }
- else if (user_Choice == 5){
- check_sales_largerthan ();
- }
- }
- public static void enter_Data ()
- {
- int sale [] = {0,0,0,0,0};
- String name [] = {" ", " ", " ", " ", " "};
- System.out.println ("Enter Employee Name, than sale");
- try
- {
- BufferedReader in = new BufferedReader( new InputStreamReader(System.in));
- name[0] = in.readLine();
- sale [0] = Integer.parseInt( in.readLine() );
- name[1] = in.readLine();
- sale [1] = Integer.parseInt( in.readLine() );
- name[2] = in.readLine();
- sale [2] = Integer.parseInt( in.readLine() );
- name[3] = in.readLine();
- sale [3] = Integer.parseInt( in.readLine() );
- name[4] = in.readLine();
- sale [4] = Integer.parseInt( in.readLine() );
- }
- catch ( Exception e )
- {
- e.printStackTrace();
- }
- System.out.println (name[0] + ": " + sale [0]);
- System.out.println (name[1] + ": " + sale [1]);
- System.out.println (name[2] + ": " + sale [2]);
- System.out.println (name[3] + ": " + sale [3]);
- System.out.println (name[4] + ": " + sale [4]);
- main_menu();
- }
- public static void total_Sales ()
- {
- System.out.println (sale [0] + sale [1] + sale [2] + sale [3] + sale [4]);
- }
- public static void average_Sales()
- {
- int average = (sale [0] + sale[1] + sale[2] + sale[3] + sale[4])/5;
- System.out.println (average);
- }
- }
any help would be appreciated.