Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package hfdst3;
- interface CallBackInterface { // added
- char getGrade();
- int getEncryptedNaam();
- }
- public class Student {
- protected String naam;
- protected int score;
- public Student(String naam, int score){
- this.naam = naam;
- this.score = score;
- }
- public String getNaam(){
- return naam;
- }
- public int getScore(){
- return score;
- }
- /*
- public char getGrade(){
- return score >= 12 ? 'A' : score < 10 ? 'C' : 'B';
- }
- public int getEncryptedNaam(){
- int e = 0;
- for(int i=0;i<naam.length();i++){
- e += (byte)(naam.charAt(i))*10;
- }
- return e;
- }
- */
- // // // //
- public CallBackInterface getCallBackReferentie() {
- return new CallBackInterface() {
- public char getGrade() {
- return score >= 12 ? 'A' : score < 10 ? 'C' : 'B';
- }
- public int getEncryptedNaam(){
- int e = 0;
- for(int i=0;i<naam.length();i++){
- e += (byte)(naam.charAt(i))*10;
- }
- return e;
- }
- };
- }
- }
- class ScoreLijst { // Student -> CallBackInterface
- protected CallBackInterface[] student;
- protected String vak;
- public ScoreLijst(CallBackInterface[] student,String vak) {
- this.student = student;
- this.vak = vak;
- }
- public String toString(){
- String r = this.vak+"\n";
- for(CallBackInterface i:student){
- r += i.getEncryptedNaam() + ":" + i.getGrade() +"\n";
- }
- return r;
- }
- }
- class Test {
- public static void main(String[] args){
- Student an = new Student("An", 9);
- Student birgit = new Student("Birgit", 16);
- Student carl = new Student("Carl", 6);
- Student dorien = new Student("Dorien", 11);
- // changed:
- ScoreLijst l = new ScoreLijst(new CallBackInterface[]{an.getCallBackReferentie(), birgit.getCallBackReferentie(), carl.getCallBackReferentie(), dorien.getCallBackReferentie()}, "Python");
- System.out.println(l);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement