CS49J Lesson 18 – Interfaces

Ch 10: 10.1-10.3

Big Java 6

When you come in

  1. Connect to the Internet
  2. Log in to Piazza
  3. Start Eclipse or your IDE
  4. Navigate to laughton.com/obrien/sjsu/
    cs49j/lessons and open this lesson

Questions

Interfaces

Allows differernt objects to make use of the same service

Concept - Java interfaces

Concept - Implementing an interface

There are two parts

 

Concept - Simplified Comparable interface

Activity - Comparable interface in the String class

Record your participation in Piazza clicker question Lesson18 Q1

Why implement the Comparable interface in your classes

Concept - Implementing the Comparable interface

Activity - Try to sort BankAccounts

Record your participation in Piazza clicker question Lesson18 Q2

Activity - Implementing Comparable interface in BankAccount

Record your participation in Piazza clicker question Lesson18 Q3

Fix the problem by implementing the Comparable interface in BankAccount.

Activity - A trick for comparing doubles

Record your participation in Piazza clicker question Lesson18 Q4

 

Activity - Implementing Comparable interface in Student

Record your participation in Piazza clicker question Lesson18 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.

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

 

Activity - Casting

Record your participation in Piazza clicker question Lesson18 Q6

In ComparableTester, Student objects are in a Comparable array.

 

Activity - Creating Comparable objects

Record your participation in Piazza clicker question Lesson18 Q7

What will happen when you try to compile these statement

 

Activity - Limits of the Comparable interface

Record your participation in Piazza clicker question Lesson18 Q8

Can you use the Arrays.sort to find the Rectangle with the largest area in an array of rectangles by sorting the array?

  1. Yes
  2. No
  3. It depends