<pre lang="java">
package aggregationlatest;
public class AggregationLATEST {
public static void main(String[] args) {
Student student1=new Student("JOHN SNOW",88,1);
School s1= new School("XYZ","Torronto",12,1000,student1);
Bus b1=new Bus("CA 1101","START","END",50,200);
s1.createClass();
s1.display();
student1.busDetail(b1);
}
}
class School
{
String name;
String address;
int maxClass;
int strength;
Class c1;
Student s1;
School(String name,String address,int maxClass,int strength,Student first)
{
this.name=name;
this.address=address;
this.maxClass=maxClass;
this.strength=strength;
s1=first;
}
class Class
{
String name;
int Boysstrength;
int girlsStrength;
String classTeacher;
Class(String name,int Boysstrength,int girlsStrength,String classTeacher)
{
this.name=name;
this.Boysstrength=Boysstrength;
this.girlsStrength=girlsStrength;
this.classTeacher=classTeacher;
}
void totalStrength()
{
System.out.println("total strengthis " + (Boysstrength + girlsStrength));
}
}
void createClass()
{
c1=new Class("1st",12,12,"CERSI LANISTER");
}
void display()
{
System.out.println(name+" "+address+" "+maxClass+" "+strength);
System.out.println(c1.name+" "+c1.Boysstrength+" "+c1.girlsStrength+" "+c1.classTeacher);
System.out.println(s1.name+" "+s1.lastPERCENTAGE+" "+s1.rollNo);
c1.totalStrength();
}
}
class Student
{
String name;
int lastPERCENTAGE;
int rollNo;
Student(String name,int lastPERCENTAGE,int rollNo)
{
this.name=name;
this.lastPERCENTAGE=lastPERCENTAGE;
this.rollNo=rollNo;
}
void busDetail(Bus b1)
{
System.out.println(b1.busLicencePlate+" "+b1.endPoint+" "+b1.maxStrength+" "+b1.monthlyCharge);
}
}
class Bus
{
String busLicencePlate;
String startingPoint;
String endPoint;
int maxStrength;
int monthlyCharge;
Bus(String busLicencePlate,String startingPoint,String endPoint,int maxStrength,int monthlyCharge)
{
this.busLicencePlate=busLicencePlate;
this.startingPoint=startingPoint;
this.endPoint=endPoint;
this.maxStrength=maxStrength;
this.monthlyCharge=monthlyCharge;
}
}
What I have tried:
I have tried to implement aggregation, association and composition .Look at the comment to see which is where .
Question
1.Is this class model wright?
2.Is the implementation is wright?
3.what will be your suggestion to improvement this code ?