/*5.
In a college first year class are having the following attributes Name of the
class (BCA, BCom, BSc), Name of the staff No of the students in the class, Array
of students in the class. Define a class called first year with above attributes
and define a suitable constructor. Also write a method called best Student ()
which process a first-year object and return the student with the highest total
mark. In the main method define a first-year object and find the best student
of this class*/
import java.io.*;
import java.lang.*;
import java.util.*;
class Student
{
int total;
String name,department;
public Student(int total,String name,String department)
{
this.total=total;
this.name=name;
this.department=department;
}
public String toString()
{
return this.total+" "+this.name+" "+this.department;
}
}
class Sortbyname implements Comparator< Student>
{
public int compare(Student a,Student b)
{
return a.name.compareTo(b.name);
}
}
class Beststudent implements Comparator< Student>
{
public int compare(Student a,Student b)
{
return b.total-a.total;
}
}
class Program5new
{
public static void main (String[]args)
{
ArrayList< Student>ar=new ArrayList< Student>();
ar.add(new Student(340,"Anil","BCA"));
ar.add(new Student(450,"Mayank","BCA"));
ar.add(new Student(360,"Anshul","BCA"));
ArrayList< Student>arbsc=new ArrayList< Student>();
arbsc.add(new Student(230,"Solanki","BSC"));
arbsc.add(new Student(411,"Aggarwal","BSC"));
arbsc.add(new Student(311,"Aggarwal","BSC"));
ArrayList< Student>arbcom=new ArrayList< Student>();
arbcom.add(new Student(220,"Solanki","BCOM"));
arbcom.add(new Student(431,"Aggarwal","BCOM"));
arbcom.add(new Student(141,"nav","BCOM"));
System.out.println("Unsorted");
for(int i=0;i< ar.size();i++)
System.out.println(ar.get(i));
for(int i=0;i< arbsc.size();i++)
System.out.println(arbsc.get(i));
for(int i=0;i< arbcom.size();i++)
System.out.println(arbcom.get(i));
Collections.sort(ar,new Beststudent());
Collections.sort(arbsc,new Beststudent());
Collections.sort(arbcom,new Beststudent());
System.out.println("High Score:");
System.out.println(" "+ar.get(0));
System.out.println(" "+arbsc.get(0));
System.out.println(" "+arbcom.get(0));
#Collections.sort(ar,new Sortbyname());
#System.out.println("\nSorted by name");
#for(int i=0;i< ar.size();i++)
#System.out.println(ar.get(i));
}
}