'Calling a method from one class to another to get its value
package Multiplemethods;
import java.util.stream.DoubleStream;
public class TimeOffice {
public static void main(String args[]){
//instance variables
double[] intime = {09.34,09.56,09.00,08.55};
double[] outtime = {17.25,18.06,17.55,16.00};
double[] loginhours = new double[intime.length];
//subtracting two arrays
int i;
for(i=0;i<intime.length;i++)
loginhours [i] = outtime[i]-intime[i];
for(int j =0; j< loginhours.length; j++)
System.out.print("Login hours=" + loginhours[j] + ",");
//sum working hours calculation
double sum = DoubleStream.of(loginhours).sum();
System.out.println("Total workinghours="+ sum);
//average working hours calculation
double average = sum/4;
System.out.println("Average working hours=" + average);
//instant variable (leave) Total leaves calculation
int leave = 2;
int Totalleaves = leave +1;
System.out.println("Total leaves taken=" + Totalleaves);
}
public class Payroll extends TimeOffice{
//instance variables
int level = 3;
int basicpay = 12000;
int BOA = 9000 ;
int Bonus = 3000 ;
}
}
I have calculated the average of loginhours in the class TimeOffice. Now, I have created a new class called Payroll and want to call the method average here, so that I can give proceed with if conditions.
Thanks in advance
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
