无法打印出String()获取null

时间:2015-02-13 13:06:01

标签: java

我有一个程序可以打印学生及其考试成绩等等。 但我有一个问题。 打印应该是:

  

Anna Andersson anna@mmail.com UPPGIFTER:4 5 6 2 6 8 9 3 SUMMA:43   BETYG:VGGODKÄND:真的

     

Bengt Bengtsson bengt@umu.se UPPGIFTER:6 0 0 1 4 6 6 1 SUMMA:24 BETYG:GGODKÄND:true

     

Cecilia Carlsson cilla@ccc.se UPPGIFTER:2 3 4 0 0 0 1 3 SUMMA:13 BETYG:UGODKÄND:   假

但是印刷是:

  

null null null UPPGIFTER:4 5 6 2 6 8 9 3 SUMMA:43 BETYG:VGGODKÄND:   真的

     

Anna Andersson anna@mmail.com UPPGIFTER:6 0 0 1 4 6 6 1 SUMMA:   24 BETYG:GGODKÄND:真的

     

Bengt Bengtsson bengt@umu.se UPPGIFTER:2 3 4 0 0 0 1 3 SUMMA:13 BETYG:U   GODKÄND:假

我得到NULL NULL NULL,其中Anna应该是,而Cecilia缺失。

这是一个实现接口的类。

public class Grade implements GradeInterface {

    String firstName;
    String lastName;
    String email;
    String TrueFalse;
    String utskrift;
    String betyget;
    int sum = 0;
    boolean TF;
    String formatedString;

    @Override
    public void setUp(StudentInterface student, List<Integer> sumsForPartialAssignment, AssignmentInterface assignment) throws IllegalArgumentException {
        firstName = student.getFirstName();
        lastName = student.getLastName();
        email = student.getEmail();



        for (int i = 0; i < sumsForPartialAssignment.size(); i++) {
            sum += sumsForPartialAssignment.get(i);
        }
        betyget = assignment.getGrade(sum);

        TrueFalse = assignment.getGrade(sum);
        TF = TrueFalse.equals(GradesConstants.pass) || TrueFalse.equals(GradesConstants.passWithDistinction);

        formatedString = sumsForPartialAssignment.toString().replace(",", "").replace("[", "").replace("]", "");

       System.out.println(toString());

    }

    @Override
    public String getGrade() {

        return TrueFalse;

    }

    @Override
    public int getSum() {
        return sum;

        }

    @Override
    public boolean hasPassed() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public String toString() {
        utskrift = (firstName + " " + lastName + " " + email + " " + "UPPGIFTER: " + formatedString + " " +  "SUMMA: " + sum + " " + "BETYG: " + betyget + " " + "GODKÄND: " + TF);
        return utskrift;
    }
}

0 个答案:

没有答案