L09b

Due by the end of this meeting

Starter Files:


SUBMIT   /   Submission Summary

Restricted Generic Types

Activity 1
Make a program called Activity1 with a method to check whether a List<String> is sorted. Test it with the following code:
List<String> one = Arrays.asList("1", "4", "4", "Elephant"); List<String> two = Arrays.asList("aardvark", "Banana"); List<String> three = Arrays.asList("Dumb", "Dumber"); System.out.println(isSorted(one)); System.out.println(isSorted(two)); System.out.println(isSorted(three));

Your output should be

true false true
Activity 2
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
Your grade will be based on the following rubric:

Submit this/these files:


SUBMIT   /   Submission Summary