CMPUT 301

Software Engineering

Practice w23am1q1


Java to UML Class Diagram

Convert this Java code to a UML class diagram. This Java code is meant to represent passengers and buses in the fictional world of My Neighbour Totoro. A Catbus can take passengers to places like a regular bus, but it also behaves like a cat. There is one specific kind of passenger (Totoro) that can ask the Catbus to do things for him.

Draw a well-designed UML class diagram to represent this information. Provide the basic abstractions, attributes, methods, relationships, multiplicities, and navigabilities as appropriate. "...” means much code is omitted.

public abstract class Bus {
    private String sign; // destination sign (e.g. "Hospital")
    private ArrayList<Passenger> passengers;
    public Bus(String sign) {
        this.sign = sign;
        this.passengers = new ArrayList<Passenger>();
    }
    public abstract void load(Passenger p);
    public abstract boolean travel(Location from, Location to);
}

public interface CatLike {
    public void purr();
}

public class CatBus extends Bus implements CatLike {
    public CatBus(String sign) {
        super(sign);
    }
    public void load(Passenger p) {
        // ...
    }
    public boolean travel(Location from, Location to) {
        // ...
        return true;
    }
    public void purr() {
        // ...
    }
}

public interface Location {
    // ...
}


public interface Passenger {
    // ...
}

public class Totoro implements Passenger {
    // Totoro is the only King of the Forest
    // He doesn’t only ride Catbuses, but can control them
    public void controlCatBus(CatBus bus) {
        // ...
    }
}