0

calculating wages

i need help to be able to calculate the wages of the employees entered. https://code.sololearn.com/cu9iXOyEOzPo/?ref=app

21st Sep 2021, 4:49 PM
Bobby Dike
Bobby Dike - avatar
9 Antworten
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
21st Sep 2021, 5:28 PM
Bobby Dike
Bobby Dike - avatar
21st Sep 2021, 5:50 PM
Bobby Dike
Bobby Dike - avatar
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];
21st Sep 2021, 6:55 PM
zemiak
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(); }
21st Sep 2021, 6:57 PM
zemiak
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]); } //} } }
21st Sep 2021, 6:57 PM
zemiak
0
better solution is write class Employee and input all data for one employee in one step of loop then one loop is enough
21st Sep 2021, 7:00 PM
zemiak
0
you can delete your first and second answer (reaction) as useless
21st Sep 2021, 7:07 PM
zemiak
0
could you write the code?
22nd Sep 2021, 1:06 PM
Bobby Dike
Bobby Dike - avatar
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() ); } } }
22nd Sep 2021, 6:06 PM
zemiak