1
테스트 성적과 그 컷오프를 인쇄하기위한 배열을 만들고 있습니다. 그러나, 때마다 내 출력은 이것이다 :시험 성적 배열을 어떻게 출력합니까?
난 그렇게 출력이 시험 성적과 단절입니다 변경해야합니까[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
?
public class Grade
{
private String grades;
private int cutoff;
//-----------------------------------------------------------------
// Stores the possible grades and their numeric lowest value.
//-----------------------------------------------------------------
public Grade (String average, int lowvalue)
{
grades = average;
cutoff = lowvalue;
}
//-----------------------------------------------------------------
// Returns the possible grades and their lowest numeric value.
//-----------------------------------------------------------------
public String getGrades (String grades, int cutoff)
{
return grades + "\t" + cutoff;
}
}
드라이버 클래스 :
public class GradeRange
{
//-----------------------------------------------------------------
// Stores the possible grades and their numeric lowest value,
// then prints them out.
//-----------------------------------------------------------------
public static void main (String[] args)
{
Grade[] score = new Grade[12];
score[0] = new Grade ("A", 95);
score[1] = new Grade ("A-", 90);
score[2] = new Grade ("B+", 87);
score[3] = new Grade ("B", 83);
score[4] = new Grade ("B-", 80);
score[5] = new Grade ("C+", 77);
score[6] = new Grade ("C", 73);
score[7] = new Grade ("C-", 70);
score[8] = new Grade ("D+", 67);
score[9] = new Grade ("D", 63);
score[10] = new Grade ("D-", 60);
score[11] = new Grade ("F", 0);
for (int index = 0; index < score.length; index++)
System.out.println (score[index]);
}
}
원하는 출력은 무엇입니까 – Nkosi
'score [index]'는 등급 객체의 인스턴스가됩니다. Grade 객체에서 toString 메서드를 재정의 해보십시오. http://stackoverflow.com/questions/10734106/how-to-override-tostring-properly-in-java –
getGrades와 동일한 것을 반환하는 toString 메서드를 만들고이를 호출합니다. 어레이 항목 – Nkosi