0
calculating wages
i need help to be able to calculate the wages of the employees entered. https://code.sololearn.com/cu9iXOyEOzPo/?ref=app
9 Respuestas
0
import java.util.Scanner; // Needed for the Scanner class
public class Payroll
{
public static void main(String[] args)
{
// Create a Scanner object to read input.
Scanner keyboard = new Scanner(System.in);
// Variable Declaration
String[] name;
int number,in,num1 = 0,num2 = 0,num3 = 0,num4 = 0,num5 = 0;
int[] employeeId;
double[] workHours;
double[] payRate;
double[] wages;
// Input Section
System.out.print("Enter the number of employees: ");
number = keyboard.nextInt();
System.out.println(" ");
// Calculations
name = new String[number];
employeeId = new int[number];
workHours = new double[number];
payRate = new double[number];
wages = new double[number];
for (in = 0; in <= number; in++)
{
keyboard.nextLine();
for (int n = 0; n < name.length; n++)
{
num1++;
System.out.print("Employee(E)" + num1 +": ");
name[n] = keyboard.nextLine();
}
for (int e = 0; e < employeeId.length; e++)
{
num2++;
System.out.print("ID of E" + num2 + ": ");
employeeId[e] = keyboar
0
import java.util.Scanner;
public class Payroll {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
// Variable Declaration
String[] name;
int number, in , num1=0, num2=0, num3=0, num4=0, num5=0;
int[] employeeId;
double[] workHours;
double[] payRate;
double[] wages;
// Input Section
System.out.print("Enter the number of employees: ");
number = keyboard.nextInt();
System.out.println(" ");
// Calculations
name = new String[number];
employeeId = new int[number];
workHours = new double[number];
payRate = new double[number];
wages = new double[number];
0
//for ( in = 0; in <= number; in ++) {
keyboard.nextLine();
for (int n = 0; n < name.length; n++) {
num1++;
System.out.print("Employee(E)" + num1 + ": ");
name[n] = keyboard.nextLine();
}
for (int e = 0; e < employeeId.length; e++) {
num2++;
System.out.print("ID of E" + num2 + ": ");
employeeId[e] = keyboard.nextInt();
}
for (int w = 0; w < workHours.length; w++) {
num3++;
System.out.print("Hours for E" + num3 + ": ");
workHours[w] = keyboard.nextDouble();
}
for (int p = 0; p < payRate.length; p++) {
num4++;
System.out.print("Payrate(per hour) of E" + num4 + ": ");
payRate[p] = keyboard.nextDouble();
}
0
for (int wa = 0; wa < wages.length; wa++) {
num5++;
//System.out.print("Wages for E" + num5 + ": " + wages[wa]);
//wages[wa] = workHours[w] * payRate[p];
wages[wa] = workHours[wa] * payRate[wa];
System.out.println("Wages for E" + num5 + ": " + wages[wa]);
}
//}
}
}
0
better solution is write class Employee and input all data for one employee in one step of loop
then one loop is enough
0
you can delete your first and second answer (reaction) as useless
0
could you write the code?
0
class Employee {
String name; int id; double workHours, payRate, wage;
Employee( String name, int id, double workHours, double payRate ) {
this.name = name; this.id = id; this.workHours = workHours;
this.payRate = payRate;
wage = workHours * payRate;
}
double getWage() { return wage; }
}
public class Payroll {
Employee[] employees;
public static void main(String[] args) {
Payroll p = new Payroll();
...
p.employees = new Employee[number];
for (int n=0; n < number; n++) {
int num = n + 1;
String name; int id; double workHours; double payRate;
keyboard.nextLine();
System.out.print("\nEmployee E" + num + ": ");
name = keyboard.nextLine();
...
p.employees[n] = new Employee( name, id, workHours, payRate);
System.out.println( "Wage for E" + num + ": "
+p.employees[n].getWage() );
}
}
}