SHARE
TWEET

Untitled

a guest May 19th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package umbrella;
  2.  
  3. public interface ForFile
  4. {
  5.     public void load(String filename);
  6. }
  7.  
  8. ///////////////////////////
  9.  
  10. package umbrella;
  11.  
  12. public class Main
  13. {
  14.  
  15.     public static void main(String[] args)
  16.     {
  17.         StudentGroup a=new StudentGroup("C:\\Users\\MyPC\\eclipse-workspace\\Resident Evil\\src\\umbrella\\ole");
  18.         a.reverse();
  19.         a.over(2);
  20.         a.bestgrade();
  21.     }
  22.  
  23. }
  24.  
  25. /////////////
  26.  
  27. package umbrella;
  28.  
  29. public class Student implements Comparable<Student>
  30. {
  31.     private String name;
  32.     private String fname;
  33.     private String fnom;
  34.     private double grade;
  35.    
  36.     public Student(String a, String b, String c, double d)
  37.     {
  38.         name=a;
  39.         fname=b;
  40.         fnom=c;
  41.         grade=d;
  42.     }
  43.    
  44.     public String get_name() { return name; }
  45.     public String get_fname() { return fname; }
  46.     public String get_fnom() { return fnom; }
  47.     public double get_grade() { return grade; }
  48.    
  49.     public void set_name(String a) { name=a; }
  50.     public void set_fname(String a) { fname=a; }
  51.     public void set_fnom(String a) { fnom=a; }
  52.     public void set_grade(double a) { grade=a; }
  53.    
  54.     public String toString()
  55.     {
  56.         return "\nFirst name: "+name+"\n"+"Last name: "+fname+"\n"+"Fac Number: "+fnom+"\n"+"Grade: "+grade+"\n";
  57.     }
  58.    
  59.     @Override
  60.     public int compareTo(Student a)
  61.     {
  62.         if(grade<a.grade) return -1;
  63.         else if(grade>a.grade) return 1;
  64.         else return 2;
  65.     }
  66.    
  67.     public boolean equals(Student a)
  68.     {
  69.         if(fnom.equals(a.fnom)) return true;
  70.         else return false;
  71.     }
  72.    
  73. }
  74.  
  75. /////////////////////////////////////
  76.  
  77. package umbrella;
  78.  
  79. import java.io.File;
  80. import java.util.ArrayList;
  81. import java.util.Collections;
  82. import java.util.List;
  83. import java.util.Scanner;
  84. import java.util.TreeSet;
  85.  
  86. public class StudentGroup implements ForFile
  87. {
  88.     private TreeSet<Student>students = new TreeSet<Student>();
  89.    
  90.     public void load(String filename)
  91.     {
  92.          try
  93.          {
  94.              Scanner file=new Scanner(new File(filename));
  95.            
  96.              while(file.hasNextLine())
  97.              {
  98.                 students.add(new Student(file.next(), file.next(), file.next(), file.nextDouble()));
  99.              }
  100.            
  101.              file.close();
  102.          }
  103.    
  104.          catch(Exception e)
  105.          {
  106.               System.out.println("Something went wrong.");
  107.          }
  108.          
  109.     }
  110.    
  111.     StudentGroup(String filename)
  112.     {
  113.         load(filename);
  114.     }
  115.  
  116.     public void print()
  117.     {
  118.             System.out.print(students.toString());
  119.     }
  120.    
  121.     public void add(Student a)
  122.     {
  123.         students.add(a);
  124.     }
  125.    
  126.     public void reverse()
  127.     {
  128.         List<Student> list = new ArrayList<Student>();
  129.         list.addAll(students);
  130.         Collections.reverse(list);
  131.         System.out.print(list.toString());
  132.     }
  133.    
  134.     public void bestgrade()
  135.     {
  136.         System.out.println("Highest grade is : " + students.last());
  137.     }
  138.    
  139.     public void over(int after)
  140.     {
  141.         List<Student> list = new ArrayList<Student>();
  142.         list.addAll(students);
  143.         int count=list.size()-after;
  144.         System.out.print("\n The size is: "+count+"\n");
  145.     }
  146.  
  147. }
  148.  
  149. ////////////////////////////////////////////////////
  150.  
  151. ole
  152.  
  153. Leon Kennedy 16121612 6
  154. Chris Redfield 11213616 3
  155. Jill Valentine 1152151 5
  156. Claire Redfield 15151 4
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top