Using Interfaces

Example:

public static void checkItems(Ownable[] items, Owner anOwner) { 
    for (int i = 0; i < items.length; i++) 
        if (!anOwner.equals(items[i].owner()))
            System.out.println(anOwner + " does not own " + 
                               items[i] + ", " + items[i].owner() + " does");
}

Example:

public static double totalValueInsured(Insurable[] items, Owner anOwner) {















}

Example:

public static void main(String[] args) { 
    // for all these constructors, assume that the first 
    // parameter is the owner and that the toString method
    // of the Owner class returns the name 
    
    Owner chris = new Owner("Chris");
    Owner alex = new Owner("Alex");
    Car usedCar = new Car(alex, ...); 
    userCar.updateOwner(chris);
    
    // assume License implements the Ownable interface
    License lic1 = new License(chris, ...); 
    License lic2 = new License(alex, ...); 
    lic2.updateOwner(chris);
    
    // assume Computer implements the Ownable and Insurable interfaces 
    Computer laptop = new Computer(chris, 2300.00, ...); 
    Computer notebook = new Computer(alex, 1950.00, ...); 
    Computer desktop = new Computer(chris, 799.00, ...); 
    
    Ownable[] stuff = {lic1, lic2, usedCar, laptop, notebook, desktop}; 
    checkItems(stuff, chris); 
     
    // code to determine the value of the items Chris needs to insure 
    
    
    
    
    
    
    
}