A company dealing with marketing wants to manage the data of its employees. Each employee has a full name, unique employee number (2019000 to 2019999) and the number of hours he worked and her hourly wage (price).
import java.util.Scanner;
public class Main {
public static double calSal(int Hr, double HrWage) {
return HrWage * Hr;
}
public static double calcAve(double[] Sal) {
return calAmount(Sal) / Sal.length;
}
public static double calAmount(double[] Sal) {
double sum = 0;
for (double salary : Sal) {
sum += salary;
}
return sum;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter the number of employees:");
int n = Integer.parseInt(in.nextLine());
String[] names = new String[n];
int[] Enums = new int[n];
int[] numHr = new int[n];
double[] hourlyWages = new double[n];
double[] Sal = new double[n];
for (int i = 0; i < n; i++) {
System.out.println("Name:");
names[i] = in.nextLine();
System.out.println("Employee number:");
Enums[i] = Integer.parseInt(in.nextLine());
System.out.println("Number of hours:");
numHr[i] = Integer.parseInt(in.nextLine());
System.out.println("Hourly wage:");
hourlyWages[i] = Double.parseDouble(in.nextLine());
Sal[i] = calSal(numHr[i], hourlyWages[i]);
}
for (int i = 0; i < n; i++) {
System.out.println(names[i] + " " + Enums[i] +
" " + numHr[i] +
"h " + hourlyWages[i] + "$/h " + Sal[i] + "$");
}
System.out.println("Average: " + calcAve(Sal) +
" Total: " + calAmount(Sal));
}
}
Comments
Leave a comment