如何输出这组考试成绩?
How do I output this array of test grades?
我正在创建一个数组来打印测试成绩及其截止日期。但是,每次我的输出都是这样的:
Grade@9c7e21
Grade@6194f8
Grade@258f60
Grade@418c57
Grade@1937e44
Grade@193a307
Grade@1a6cfa1
Grade@5b7a7
Grade@950d76
Grade@dceda6
Grade@102f6c0
Grade@681b92
我应该更改什么以便输出是测试成绩和截止值?
这是我的 2 classes:
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;
}
}
Driver class:
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]);
}
}
将 toString
方法添加到成绩 class
public String toString() {
return grades + "\t" + cutoff;
}
并在for循环中使用它
for (int index = 0; index < score.length; index++)
System.out.println (score[index].toString());
我正在创建一个数组来打印测试成绩及其截止日期。但是,每次我的输出都是这样的:
Grade@9c7e21
Grade@6194f8
Grade@258f60
Grade@418c57
Grade@1937e44
Grade@193a307
Grade@1a6cfa1
Grade@5b7a7
Grade@950d76
Grade@dceda6
Grade@102f6c0
Grade@681b92
我应该更改什么以便输出是测试成绩和截止值?
这是我的 2 classes:
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;
}
}
Driver class:
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]);
}
}
将 toString
方法添加到成绩 class
public String toString() {
return grades + "\t" + cutoff;
}
并在for循环中使用它
for (int index = 0; index < score.length; index++)
System.out.println (score[index].toString());