CS49J Lesson 13 – Designing classes

Ch 8: 8.1-8.3
Ch 12: 12.1-12.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

Concept - What makes a good class?

 

Activity - Picking classes

Record your participation in Piazza clicker question Lesson13 Q1

We are simulating a public library with books that can be checked out and returned. Each book has an author and an indication of whether it is on the shelf. A patron can check out and return books. Which of these would be good classes. Check all that are appropriate

  1. Read
  2. Book
  3. Author
  4. Checkout
  5. Library
  6. IsOnShelf
  7. Patron

 

Activity - Cohesive public interface

Record your participation in Piazza clicker question Lesson13 Q2

You are designing a class CreditCard as part of a credit card services program. Which of these methods would you include in the public interface to make the class cohesive? Check all that apply.

  1. makePayment
  2. getCustomerAddress
  3. charge
  4. getSafetyDepositBoxNumber
  5. calculateMonthlyFees
  6. getAllThisCustomerAccounts

 

Activity - Problematic method

Record your participation in Piazza clicker question Lesson13 Q3

What is wrong with this method of the Book class? May be more than one answer

public void isOnShelf
{
   if (onShelf)
   {
      System.out.println("The book is on the shelf");
   }
   else
   {
      System.out.println("The book is NOT on the shelf");
   }

}
  1. introduces a dependency
  2. has a side effect
  3. is not cohesive
  4. combines a mutator and an accessor

 

Concept - Design Patterns

Activity -

Record your participation in Piazza clicker question Lesson13 Q4

You are writing a Student class with instance variables studentID, name, gpa which is calculated in a updatGpa method.

Which instance variables should have both a getter and a setter? Check all that apply

  1. studentID
  2. name
  3. gpa

Concept - Relationships between classes

 

Activity - Relationships between classes

Record your participation in Piazza clicker question Lesson13 Q5

Think of a pair of classes that demomstrate one of the types of relationships