Skip to content

Instantly share code, notes, and snippets.

@mhaidarhanif
Created September 25, 2015 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhaidarhanif/665807229a58ea95f69d to your computer and use it in GitHub Desktop.
Save mhaidarhanif/665807229a58ea95f69d to your computer and use it in GitHub Desktop.
Student Grading
public class Grade {
public String gradeScore(int score) {
String result = "";
if (score >= 60) {
result = "lulus";
} else if (score >= 40) {
result = "nyaris lulus";
} else if (score >= 0) {
result = "tidak lulus";
} else if (score < 0) {
result = "tidak jelas";
}
return result;
}
}
public class RunGrading {
public static void main(String[] args) {
Student adi = new Student("Adi", 90);
Student budi = new Student("Budi", 20);
Student ceri = new Student("Ceri", 0);
Student debi = new Student("Debi", 60);
Student endi = new Student("Endi", -10);
Student[] students = new Student[5];
students[0] = adi;
students[1] = budi;
students[2] = ceri;
students[3] = debi;
students[4] = endi;
Grade grader = new Grade();
for (int x = 0; x < students.length; x++) {
System.out.print( students[x].getName() + " nilainya " + students[x].getScore() );
System.out.println( " dinyatakan " + grader.gradeScore(students[x].getScore()) );
}
}
}
public class Student {
public String name;
public int score;
public Student(String name, int score) {
this.name = name;
this.score = score;
}
public String getName() {
return this.name;
}
public int getScore() {
return this.score;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment