Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. /*
  2. * Title:
  3. *
  4. * Description:
  5. *
  6. * Author: Meggan Vyanh Do
  7. * Created:
  8. * Updated:
  9. */
  10. package assignment2;
  11.  
  12. import java.util.ArrayList;
  13. import java.util.Collections;
  14. import java.util.Comparator;
  15.  
  16. public class TestCourse
  17. {
  18.  
  19. public static void main(String[] args)
  20. {
  21. // creating the course arraylist
  22. ArrayList<Course> courses = new ArrayList<Course>();
  23.  
  24. // adding the courses to the array the more efficient way
  25. courses.add(new Course("PROG24178","Object-Oriented Programming 2 - Java",6,"PROGRAMMING"));
  26. courses.add(new Course("MATH14998","Computer Math 1",4,"MATH"));
  27. courses.add(new Course("SYST10082","Operating Systems Fundamentals",3,"SYSTEM"));
  28. courses.add(new Course("INFO10229","Mobile Computing",3,"INFORMATION"));
  29. courses.add(new Course("DBAS14444","Structured Database Modelling ",3,"DATABASE"));
  30.  
  31.  
  32. // print array
  33. for(int i=0; i<courses.size(); i++){
  34. System.out.println(courses.get(i));
  35. }
  36. System.out.println();
  37.  
  38. //sorting by id
  39.  
  40. class StringComparator implements Comparator<Course>
  41. {
  42. @Override
  43. public int compare(Course s1, Course s2)
  44. {
  45. return s1.getId().length() - s2.getId().length();
  46. }
  47. }
  48.  
  49.  
  50.  
  51.  
  52. //sorting by title
  53.  
  54.  
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement