현재 Java 프로그래밍 클래스의 과제를 진행하고 있습니다. 나는 나 자신을 조금 묶어 놓은 것처럼 보인다. 내가 뭘 잘못하고 있는지 깨닫도록 돕는 데 도움이된다면 크게 감사 할 것입니다.학교 과제 다차원 배열 문제
할당
는 다음을 수행하는 프로그램 작성 :
다중 차원 배열
에 아래의 데이터를 넣어은 직원의 급여 통계를하고자하는 회사에 대한하라는 메시지를 표시합니다.
평균 직원 급여를 이중으로 반환하는 방법을 작성하십시오. 회사 번호와 직원 임금을이 방법에 전달하십시오.
총 직원 급여를 int로 반환하는 메소드를 작성하십시오. 회사 번호와 직원 임금을이 방법에 전달하십시오.
직원 수를 int로 반환하는 메서드를 작성합니다. 회사 번호와 직원 임금을이 방법에 전달하십시오.
기본 메소드에서 다른 메소드를 호출하고 결과를 출력하십시오.
저는 여전히 새롭고 프로그래밍 원칙을 이해하는 데 어려움을 겪습니다.
내가 대신 방법 계산의 위치를 얻고 프로그램 (나쁜 출력)를 실행하면 :
여기내가 지금까지 무엇을 가지고 :
package salaries;
import java.util.Scanner;
public class Salaries {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
//declare, instantiate, and define value of multi array [3] [12]
double [][] mSalary = { { 49920, 50831, 39430, 54697, 41751, 36110,
41928, 48460, 39714, 49271, 51713, 38903},
{ 45519, 47373, 36824, 51229, 36966, 40332,
53294, 44907, 36050, 51574, 39758, 53847},
{ 54619, 48339, 44260, 44390, 39732, 44073,
53308, 35459, 52448, 38364, 39990, 47373}};
//declare, instantiate, and define value
//of single array for company names
//and output values to user for selection
String [] company = { "Alhermit", "Logway", "Felter" };
for(int i = 0; i < company.length; i++)
System.out.println("Company " + i + " : " +company[i]);
Scanner scan = new Scanner(System.in);
int cCompany;
do{
//ouput for user to select a company
System.out.print("Select company: (0)" +company[0]+ ", (1)"
+company[1]+ "; (2)" +company[2]+ " > ");
//scan user input into cCompany
cCompany = scan.nextInt();
//call number method
num nums = new num();
nums.number(mSalary, cCompany);
//call total method
total sum = new total();
sum.total(mSalary, cCompany);
//call average method
avg cAvg = new avg();
cAvg.average(mSalary, cCompany);
//output statistics to user on selected company
System.out.println("You have selected the company " + company[cCompany] + ". ");
System.out.println(company[cCompany] + " has " + nums + " of employees.");
System.out.println("A total employee salary of " + sum + ".");
System.out.println("The average employee salary is " + cAvg);
}
while(cCompany < 0 || cCompany > 2);
}
}
//total class to calculate
//salary of user selected company
class total {
public static int total(double [][] mSalary, int cCompany){
//assign variables
int sum = 0;
//for loop to calculate salary total of user input company
for(int j = 0; j < mSalary[cCompany].length; j++){
sum += mSalary[cCompany][j];
}
//return statement
return sum;
}
}
//average class to calculate
//average of user selected company
class avg {
public static double average(double [][] mSalary, int cCompany){
//assign variables
int cAvg = 0;
int sum = 0;
int count = 0;
//totals the values for the selected company by
//iterating through the array with count.
while(count < mSalary[cCompany].length){
sum += mSalary[cCompany][count];
count +=1;
}
cAvg = sum/mSalary[cCompany].length;
return cAvg;
}
}
//number class to calculate amount of
//employees in user selected company
class num {
public static int number(double [][] mSalary, int cCompany){
//assign variables
int nums = 0;
//number of employees based on length of colomn
nums = mSalary[cCompany].length;
return nums;
}
}
"나쁜 출력"이미지에 링크합니다 (이미지를 사용하지 말고 질문에 텍스트로 포함). 그러나 "올바른 출력"이 무엇인지는 말하지 않았습니다. 당신이 현재 붙잡고있는 과제의 어느 단계도 아닙니다. –
잘못된 클래스 이름, 잘못된 들여 쓰기, 일치하지 않는 공백을 포함하여 많은 스타일 문제가 있습니다. –