嗨即時製作這個程序,創建員工和保存他們的信息。我在一個類中做出這種方法來存儲一些它接收到的信息,但問題是,它會覆蓋被傳遞的信息,這是方法`在多維替換信息
int employeeSize = 1;
public void employeeInfo(int ID , double hours, int salary){
double [][] empInfo = new double[employeeList.size()][3];
for(int row = 0; row < empInfo.length; row++){
empInfo[ID-1][0] = ID;
}
for(int row = 0; row < empInfo.length; row++){
empInfo[ID-1][1] = hours;
}
for(int row = 0; row < empInfo.length; row++){
empInfo[ID-1][2] = Double.parseDouble(f.format(getPay(hours, salary)));
}
//if(employeeSize == employeeList.size()){
printInfo(empInfo);
totalPay(empInfo);
totalHours(empInfo);
//}
employeeSize++;
}`
這是它被如何使用的其他班級,它會根據有多少員工被添加,並且其他信息通過,要求員工花費很多時間。
for(int i = 0; i <employeesToAdd; i++){
double hours = getADouble(scanner, "\nEnter the hours for "+employees.names(i)+": > ");
employees.employeeInfo(employees.id(i), hours,employees.getSalary(i));
}
這是它被打印的結果。
Enter the hours for j: > 42
1.0 42.0 1757.21 0.0 0.0 0.0
This is the total pay: 1757
This is the total hour: 42.0
Enter the hours for d: > 41
0.0 0.0 0.0 2.0 41.0 1296.88
This is the total pay: 1296
This is the total hour: 41.0
我想也格式化打印出來是
Enter the hours for j: > 42
Enter the hours for d: > 41
1.0 42.0 1757.21
2.0 41.0 1296.88
This is the total pay: 3054
This is the total hour: 83.0
這是打印陣列
public void printInfo(double[][]array){
for(int i = 0; i < array.length; i++){
for(int j = 0; j < array[i].length; j++){
System.out.print("\t"+array[i][j]);
}
}
}
你的意思是被覆蓋的信息是什麼意思?也許讓他們不可變? – lenhuy2106