2 Replies - 198 Views - Last Post: 16 June 2015 - 02:40 PM Rate Topic: -----

#1 Demongo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 16-June 15

Employee Salary Calculator

Posted 16 June 2015 - 02:08 PM

I'm not sure whats going on. I am not getting any errors, but after line 38....nothing happens. I am new to this whole java/ programming thing. A nudge in the right direction would be most appreciated because I am at my wits ends with this thing. It is suppose to ask for a company and then provide the sum of the column, the avg, and then the number of employees. I don't want it done for me, I am just in over my head with these multidimentional arrays.

mport java.util.Scanner;
import java.text.NumberFormat;


public class comp 
{
  public static void main (String [ ] args )
  {
       
           

   //multidiementional array with employeeSalary data
   int[][] employeeSalary = new int[][] {  { 49920, 45519, 54619},
                                           { 50831, 47373, 48339},
                                           { 39430, 36824, 44260},
                                           { 54697, 51229, 44390},
                                           { 41751, 36966, 39732},
                                           { 36110, 40332, 44073},
                                           { 41928, 53294, 53308},
                                           { 48460, 44907, 35459},
                                           { 39714, 36050, 52448},
                                           { 49271, 51574, 38364},
                                           { 51713, 39758, 39990},
                                           { 38903, 53847, 47373} };
             
      

       
                                
       //lets you select a company
       String [] compName = { "Alhermit", "Logway", "felter" };
        for ( int i = 0; i < compName.length; i++ )
        System.out.println( " Company Number " + i + " : " + compName [i] );
                
        Scanner scan = new Scanner( System.in );
        int currentName;
        do
        {
         System.out.print( "Select Company Number > ");
         currentName = scan.nextInt( );
        }while ( currentName < 0 || currentName > 2);
        }
      //calculates and prints total employeeSalary of chosen company
      public int salTot(int n,int[][] employeeSalary )
   {
       int sum=0;
       int leng=employeeSalary[n].length;
       for(int i=0;i<leng;i++)
           sum=sum+employeeSalary[n][i];
      System.out.println("Total Salary is: "+sum);
       return sum;
   }
     //calculates and prints out avg of selected company
       public double salAvg(int n,int[][] employeeSalary )
   {
       double avg=0;
       int sum=0;
       int leng=employeeSalary[n].length;
       for(int i=0;i<leng;i++)
           sum=sum+employeeSalary[n][i];
       avg=sum/leng;
      System.out.println("Average Salary is: "+avg);
       return avg;
   }
     //calculates and prints total employees
     public int totEmp(int n,int[][] employeeSalary )
   {
       int leng=employeeSalary[n].length;
       System.out.println("Number of employees is: " +leng );
       return leng;  
       
           
       }
   
}
 


line 43 and on isn't working...I am not sure what I am not doing right to get it to initialize

This post has been edited by macosxnerd101: 16 June 2015 - 02:07 PM
Reason for edit:: Renamed title to be more descriptive


Is This A Good Question/Topic? 0
  • +

Replies To: Employee Salary Calculator

#2 macosxnerd101  Icon User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 11248
  • View blog
  • Posts: 42,314
  • Joined: 27-December 08

Re: Employee Salary Calculator

Posted 16 June 2015 - 02:12 PM

Welcome to Dream.in.Code! :)

Note that any code in your main() method gets executed. So the last statements in your main() method are the loop to prompt for the index of the company. You don't tell your program to do anything after the do-loop.

You have the salTot, salAvg, and totEmp methods. You might want to invoke them (after making them static methods first).
Was This Post Helpful? 0
  • +
  • -

#3 Demongo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 16-June 15

Re: Employee Salary Calculator

Posted 16 June 2015 - 02:40 PM

View Postmacosxnerd101, on 16 June 2015 - 02:12 PM, said:

Welcome to Dream.in.Code! :)/>

Note that any code in your main() method gets executed. So the last statements in your main() method are the loop to prompt for the index of the company. You don't tell your program to do anything after the do-loop.

You have the salTot, salAvg, and totEmp methods. You might want to invoke them (after making them static methods first).



Yes yes...I think I see what your saying, thank you for the help I will work on that!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1