Results 1 to 8 of 8
  1. #1
    sara2017 is offline Member
    Join Date
    Apr 2017
    Posts
    8
    Rep Power
    0

    Default Please help..weekly earnings not working

    Java Code:
    package test;
    
    import java.util.*;
    
    public class test {
    	public static void main(String[] args) {
    		String Name[]= new String[4];
    		double hoursWorked[] =new double[4];
    		double hourlyPay[] = new double[4];
    		double WeeklyEarnings[] =new double[4];
    	
    		
    		GetInfo(Name,hoursWorked,hourlyPay);
    		WeeklyEarnings[3] = CalculateTotal(hoursWorked,hourlyPay);
    		DisplayInfo(Name,hoursWorked,hourlyPay,WeeklyEarnings);
    	
    	
    	
    	
    	}
    	 public static void GetInfo(String Name[], double hoursWorked[], double hourlyPay[])
    	 {
    		 
    		 String blank;
    		 Scanner UserIn = new Scanner(System.in);
    		 
    		 
    		 
    		 
    		 for(int i=0;i< Name.length;i++)
    		 {
    			 
    			 
    			 System.out.print("Please enter name #"+(i+1) + ":");
    			 Name[i]= UserIn.nextLine();
    			 
    			
    			 do
    			 {
    			 System.out.print("Please enter the number of hours worked:");
    			 hoursWorked[i] = UserIn.nextDouble();
    			 if(hoursWorked[i]<0)
    			 {
    				 System.out.print("Invalid entry !!! Please try again");
    			 
    			 }
    			 }while(hoursWorked[i]<0);
    		
    			 System.out.print("Please enter the hourly pay rate: ");
    			 hourlyPay[i]= UserIn.nextDouble();
    	
    			 blank= UserIn.nextLine();
    			 System.out.print("\n");
    			 
    		 } 
    	 }
    	 public static double CalculateTotal(double hoursWorked[], double hourlyPay[])
    		{
    			double[] WeeklyEarnings =new double[4];
    			
    			for(int i=0;i<hoursWorked.length;i++)
    			{
    			WeeklyEarnings[i] = hoursWorked[i] * hourlyPay[i];
    			//System.out.println(+WeeklyEarnings[i]);
    			
    			}
    			
    		
    			return WeeklyEarnings[3];
    			
    		}
    			
     public static void DisplayInfo(String Name[], double hoursWorked[], double hourlyPay[], double weeklyEarnings[])
    		 {
    		 
    System.out.print("\nName\t Hours Worked\t Hourly Pay\t Weekly Earnings");
    
    for(int i=0;i<weeklyEarnings.length;i++)
    {
    	System.out.printf("\n"+ Name[i]+"\t"     +hoursWorked[i] +"\t\t"  +"$"     +hourlyPay[i] +"\t\t" +     "$%.2f",weeklyEarnings[i]);
    	//System.out.println("i="+i);
    	//System.out.println("weekly =" +weeklyEarnings[i]);
    	
    }
    
    	 
    		 }
    		 
    		 
    		 
    		 
    	 }
    Last edited by Norm; 04-19-2017 at 08:00 PM. Reason: Added code tags

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Please help..weekly earnings not working

    Please place you code between code tags for formatting. See BB Codes below for help. And also state what problem(s) you are having.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    sara2017 is offline Member
    Join Date
    Apr 2017
    Posts
    8
    Rep Power
    0

    Default Re: Please help..weekly earnings not working

    there is no error showing .. I am trying to calculate weekly earnings for 4 employees by hourlyPay * Hoursworked in a method named CalculateTotal().
    for 1st 3 employees ,weekly earnings showing as 0 . only for 4th employee the calculation is showing. output as showing below. Please help.Thank You

    Name Hours Worked Hourly Pay Weekly Earnings
    ddd 4.0 $5.0 $0.00
    sdd 5.0 $6.0 $0.00
    eee 4.0 $3.0 $0.00
    ddd 4.0 $5.0 $20.00

  4. #4
    sara2017 is offline Member
    Join Date
    Apr 2017
    Posts
    8
    Rep Power
    0

    Default Re: Please help..weekly earnings not working

    Java Code:
    package test;
    
    import java.util.*;
    
    public class test {
    public static void main(String[] args) {
    String Name[]= new String[4];
    double hoursWorked[] =new double[4];
    double hourlyPay[] = new double[4];
    double WeeklyEarnings[] =new double[4];
    
    
    GetInfo(Name,hoursWorked,hourlyPay);
    WeeklyEarnings[3] = CalculateTotal(hoursWorked,hourlyPay);
    DisplayInfo(Name,hoursWorked,hourlyPay,WeeklyEarni ngs);
    
    
    
    
    }
    public static void GetInfo(String Name[], double hoursWorked[], double hourlyPay[])
    {
    
    String blank;
    Scanner UserIn = new Scanner(System.in);
    
    
    
    
    for(int i=0;i< Name.length;i++)
    {
    
    
    System.out.print("Please enter name #"+(i+1) + ":");
    Name[i]= UserIn.nextLine();
    
    
    do
    {
    System.out.print("Please enter the number of hours worked:");
    hoursWorked[i] = UserIn.nextDouble();
    if(hoursWorked[i]<0)
    {
    System.out.print("Invalid entry !!! Please try again");
    
    }
    }while(hoursWorked[i]<0);
    
    System.out.print("Please enter the hourly pay rate: ");
    hourlyPay[i]= UserIn.nextDouble();
    
    blank= UserIn.nextLine();
    System.out.print("\n");
    
    } 
    }
    public static double CalculateTotal(double hoursWorked[], double hourlyPay[])
    {
    double[] WeeklyEarnings =new double[4];
    
    for(int i=0;i<hoursWorked.length;i++)
    {
    WeeklyEarnings[i] = hoursWorked[i] * hourlyPay[i];
    //System.out.println(+WeeklyEarnings[i]);
    
    }
    
    
    return WeeklyEarnings[3];
    
    }
    
    public static void DisplayInfo(String Name[], double hoursWorked[], double hourlyPay[], double weeklyEarnings[])
    {
    
    System.out.print("\nName\t Hours Worked\t Hourly Pay\t Weekly Earnings");
    
    for(int i=0;i<weeklyEarnings.length;i++)
    {
    System.out.printf("\n"+ Name[i]+"\t" +hoursWorked[i] +"\t\t" +"$" +hourlyPay[i] +"\t\t" + "$%.2f",weeklyEarnings[i]);
    //System.out.println("i="+i);
    //System.out.println("weekly =" +weeklyEarnings[i]);
    
    }
    
    
    }
    
    
    
    
    }

  5. #5
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Please help..weekly earnings not working

    In your methods you are storing the results in an array (e.g. WeeklyEarnings). But look at what you are returning.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  6. #6
    sara2017 is offline Member
    Join Date
    Apr 2017
    Posts
    8
    Rep Power
    0

    Default Re: Please help..weekly earnings not working

    Thank You Jim.. would you please explain .I tried to return weeklyearnings, then it showing cannot convert double[] to double. am really confused

  7. #7
    sara2017 is offline Member
    Join Date
    Apr 2017
    Posts
    8
    Rep Power
    0

    Default Re: Please help..weekly earnings not working

    sorry .. i got the code correct. Thank You so much !!!!

  8. #8
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Please help..weekly earnings not working

    I knew you would figure it out.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. weekly calendar on tabpanel
    By raj18 in forum Advanced Java
    Replies: 5
    Last Post: 09-30-2009, 01:34 AM
  2. weekly salary
    By dollakay in forum New To Java
    Replies: 2
    Last Post: 05-09-2008, 02:46 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •