퀴즈 점수에 대한 프로그램을 작성하고 있는데 주 메서드에 배열이 있고 별도의 클래스에 적절한 생성자와 메서드를 제공해야합니다. "addQuizScore (int score) ","getTotalScore ". 나는 아직도 Java에 익숙하지 않고 이것을 올바르게 수행하는 방법에 매달 렸습니다.배열을 다른 클래스에 전달하는 방법
import java.util.*;
public class StudentQuiz
{
public static void main(String[] args)
{
int [] score = {7,8,5,6,0,10,7,6};
StudentQuizInfo newStudent = new StudentQuizInfo(score);
System.out.println("total score: " +newStudent.getTotalScore());
}
}
import java.util.*;
public class StudentQuizInfo {
private int overallScore = 0;
private int totalScore = 0;
public StudentQuizInfo(int[] score) {
}
public int addQuizScore(int [] score)
{
int k;
int overallScore = 0;
for(k = 0; k <score.length; k++)
{
overallScore = overallScore + score[k];
}
return overallScore;
}
int getTotalScore()
{
int totalScore = overallScore;
return totalScore;
}
}
ATM 코드가 totalscore: 0
인데 잘못 인쇄되었습니다.
현재 코드가 매우 형편 없다는 것을 알고 있으므로 어떻게 수정할 수 있습니까? 특히 addQuizScore를 올바르게 사용하는 방법에 대해 많이 고맙게 생각합니다.
StudentQuizInfo newStudent = new StudentQuizInfo(score);
후
newStudent.addQuizScore(score);
추가 덕분에
왜 넣지'addQuizScore (점수)와 같은 생성자'생성자? – johnchen902