Lesson 22 – Comparable Interface

Big Java 6

When you come in

  1. Connect to the Internet
  2. Log in to Piazza
  3. Start Bluej
  4. Navigate to laughton.com/obrien/sjsu/cs46a/CRT_lessons/ and open this lesson

Questions

Comparable interface

Activity - Comparable interface in the String class

Record your participation in Piazza clicker question Lesson22 Q1

Why implement the Comparable interface in your classes

Activity - Try to sort BankAccounts

Record your participation in Piazza clicker question Lesson22 Q2

Activity - Implementing Comparable interface in BankAccount

Record your participation in Piazza clicker question Lesson22 Q3

Let's fix the problem by implementing the Comparable interface.

Activity - A trick for comparing doubles

Record your participation in Piazza clicker question Lesson22 Q4

 

Activity - Implementing Comparable interface in Student

Record your participation in Piazza clicker question Lesson22 Q5

Add the Comparable interface to the Student class. Students are ordered by GPA. If the GPA's are the same, they are ordered by name. Uncomment the code in ComparableTester that creates the ArrayList and sorts it.

  1. Got it
  2. Got it but it was hard
  3. Didn't get it

 

Activity - Creating Comparable objects

Record your participation in Piazza clicker question Lesson22 Q6

What would happen if you tried to compile these statement