Make a program called Activity2
with a method to check whether a List of any sortable type
is sorted.
Test it with the following code:
List<Person> people = Arrays.asList(new Person("1"),
new Person("4"), new Person("4"), new Person("Elephant"));
List<Student> students = Arrays.asList(new Student("aardvark"),
new Student("Banana"));
List<Weird> weirdos = Arrays.asList(new Weird("Dumb"),
new Weird("Dumber"));
System.out.println(isSorted(people));
System.out.println(isSorted(students));
// System.out.println(isSorted(weirdos));
Make sure that the last line does not compile.
(If you remove the //
at the beginning,
it should object that method isSorted cannot be applied to the given types
(sic).
Your output should be
true
false