CMPUT 301

Software Engineering

Practice w23hm1q1


Java to UML Class Diagram

Convert this Java code to a UML class diagram. This Java code is meant to represent a mouth tasting and consuming food. There are food, flavours, tongues, and taste buds.

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.

import java.util.*;

class Mouth {
    Collection<Tooth> teeth;
    Tongue tongue;
    // ...
}
class Tooth {
    // ...
}
class Tongue {
    private TasteBud[] buds;
    Flavour taste(Food f) {
        Flavour[] flavours = new Flavour[buds.length];
        for (int i = 0; i < buds.length; i++) {
            flavours[i] = buds[i].taste(f);
        }
        return new AggregateFlavour(flavours);
    }
    // ...
}
interface TasteBud {
    public Flavour taste(Food f);
}
interface Flavour {
    public int sweet();
    public int salty();
}
class AggregateFlavour implements Flavour {
    Flavour[] flavours;
    AggregateFlavour(Flavour[] flav) {
        flavours = flav;
    }
    public int sweet() {
        // Sum of sweetness
        // ...
    }
    public int salty() {
        // Sum of salty
        // ...
    }
    // ...
}
interface Food {
    // ...
}