Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Title:
- *
- * Description:
- *
- * Author: Meggan Vyanh Do
- * Created:
- * Updated:
- */
- package assignment2;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.Comparator;
- public class TestCourse
- {
- public static void main(String[] args)
- {
- // creating the course arraylist
- ArrayList<Course> courses = new ArrayList<Course>();
- // adding the courses to the array the more efficient way
- courses.add(new Course("PROG24178","Object-Oriented Programming 2 - Java",6,"PROGRAMMING"));
- courses.add(new Course("MATH14998","Computer Math 1",4,"MATH"));
- courses.add(new Course("SYST10082","Operating Systems Fundamentals",3,"SYSTEM"));
- courses.add(new Course("INFO10229","Mobile Computing",3,"INFORMATION"));
- courses.add(new Course("DBAS14444","Structured Database Modelling ",3,"DATABASE"));
- // print array
- for(int i=0; i<courses.size(); i++){
- System.out.println(courses.get(i));
- }
- System.out.println();
- //sorting by id
- class StringComparator implements Comparator<Course>
- {
- @Override
- public int compare(Course s1, Course s2)
- {
- return s1.getId().length() - s2.getId().length();
- }
- }
- //sorting by title
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement