package my.pkg; import java.util.*; class Person { String name; String surname; Person(String name, String surname) { this.name = name; this.surname = surname; } } role Student playedby Person{ void study(int hours); int getStudiedHours(); double getAvg(); } role FrequentedCourse playedby Course { int assignVote(); int getVote(); boolean substained(); } class Person{ String name; public Person(String name){ this.name=name; } public String getName(){ return name; } definerole FrequentedCourse extends FrequentedCourses.FrequentedCourse{ public int getCfu(){ return that.getCfu(); } } } class Course{ String subject; final int cfu; Person professor; public Course(Person professor, String subject, int cfu){ this.professor = professor; this.subject=subject; this.cfu=cfu; } public int getCfu(){ return cfu; } definerole Student extends FrequentedCourses.Student{ int studiedHours; double avg; int cfuSostenuti; public Student(){ studiedHours=0; avg=0; cfuSostenuti=0; } public void study(int hours){ studiedHours+=hours; } public int getStudiedHours(){ return studiedHours; } public void riceviVote(int vote, int cfu){ avg=(avg*cfuSostenuti+vote*cfu)/((double)(cfuSostenuti+cfu)); cfuSostenuti+=cfu; } public double getAvg(){ return avg; } } } relationship FrequentedCourses{ tuple int vote=0; tuple boolean substained=false; tuple public int getVote(){ return vote; } tuple public int setVote(){ if(substained) return getVote(); substained=true; vote=(int)((to.getStudiedHours()/100.0)*12)+18; if(vote>30) vote=31; to.riceviVote(getVote(), from.getCfu()); return getVote(); } tuples public java.util.Vector appello(Course c){ java.util.Vector appello = new java.util.Vector(); for(Student s: getToSet(c)){ appello.add(s.getThat().getName()); } return appello; } tuples public double getAvg(Person p){ double avg=0; int n=0; for(FrequentedCourse c : getFromSet(p)){ if(((this.p.FrequentedCourse)c.getThat()).substained()){ avg+=c.getVote(); n++; } } return (n!=0) ? avg/n :0; } abstract definerole FrequentedCourse{ abstract int getCfu(); public int assignVote(){ return tuple.setVote(); } public int getVote(){ return tuple.getVote(); } public boolean substained(){ return tuple.substained; } } abstract definerole Student{ public abstract int getStudiedHours(); abstract void riceviVote (int vote, int cfu); } } public class Unito{ public static void main(String[] args){ FrequentedCourses unito = new FrequentedCourses(); Person feynman = new Person("Richard Feynman"); Person lorentz = new Person("Konrad Lorentz"); Person andrea = new Person("Andrea Amoretti"); Person serena = new Person("Serena Cardamone"); Person giovanni = new Person("Giovanni Coletti"); Course fisica = new Course(feynman,"fisica", 6); Course etologia = new Course(lorentz, "etologia", 6); unito.add(fisica, new Person[] {andrea, giovanni}); //abbreviations for unito.add(fisica,andrea); unito.add(fisica, giovanni )... unito.add(etologia, new Person[]{giovanni, serena}); System.out.println(unito.appello(fisica)); System.out.println(unito.appello(etologia)); ((unito.fisica.Student)andrea).study(90); ((unito.fisica.Student)giovanni).study(80); ((unito.etologia.Student)giovanni).study(30); ((unito.etologia.Student)serena).study(60); for(int i = 0;i