0

I am wondering how I would create a UML diagram from a java class that I have already wrote. One main question that I have is do I need to include all the override functions in this box of the UML diagram? Also does everything else look correct? I was very ill during the lecture of UML so I had to teach myself and am not 100% confident in my work.

Here is my java class and then I will post the diagram I made for this class.

public class Dog extends Pet implements LicensedPet, TrainedDog {

public static final String GENUS = "canis";

private Boolean isHappy = false;
private Boolean isSitting = false;
private LocalDateTime whenLicensed;

public Dog(String name, int age, Gender gender) {
    super(name, age, "dog", gender);
}

public void petDog() {
    isHappy = true;
}

public void praiseDog() {
    isHappy = true;
}

public void yellAtDog() {
    isHappy = false;
}

public Boolean getIsHappy() {
    return isHappy;
}

public String getIsHappyAsString() {
    if (isHappy) {
        return "happy";
    } else {
        return "sad";
    }
}

@Override
public String[] getCoreVaccines() {

    String[] coreVaccines = {
        "Rabies 1-year",
        "Rabies 3-year",
        "Distemper",
        "Parvovirus",
        "Adenovirus"
    };

    return coreVaccines;
}

@Override
public String[] getNonCoreVaccines() {

    String[] nonCoreVaccines = {
        "Parainfluenza",
        "Bordetella bronchiseptica",
        "Lyme disease",
        "Leptospirosis",
        "Canine influenza"
    };

    return nonCoreVaccines;
}

@Override
public Boolean isLicensed() {
    return whenLicensed != null;
}

@Override
public void assignLicense() {
    whenLicensed = LocalDateTime.now();
}

@Override
public LocalDateTime whenLicensed() {
    return whenLicensed;
}

@Override
public void sit() {
    isSitting = true;
}

@Override
public void unsit() {
    isSitting = false;
}

@Override
public String speak() {
    return "Yawyahwer";
}

@Override
public String bark(int numBarks) {
   String barks = "";
   for (int i = 0; i < numBarks; i++) {
       barks += "bark!";
   }

   return barks;
}

@Override
public String toString() {
    String info = super.toString();

   String updatedInfo =  String.format("%s, isHappy: %s", info, isHappy);

   if (whenLicensed != null) {
       updatedInfo +=  ", whenLicensed: " + whenLicensed;
   }

   return updatedInfo;
}
}

Here is what I created so far for this class.

    Dog
---------
    +GENUS:string 
    -isHappy:boolean
    -isSitting:boolean
    -whenLicensed:LocalDateTime
----------------
    +«constructor»Dog(name:string, age:int, gender:gender)
    +petDog()
    +praiseDog()
    +yellAtDog()
    +getIsHappy():boolean
    +getIsHappyAsString():string

Thanks for the help in advance i appreciate it

2

2 Answers 2

1

You can add the ObjectAid plugin to eclipse and examine the class easily in there (drag and drop onto class diagram canvas). http://www.objectaid.com/

Here's how that looks for your dog class UML for DOG

0

If you are overriding inherited class methods you should add them to your class' method compartment. You don't need to add purely inherited classes, though. I'm not that firm with the ascii representation but somewhere you need to tell the generalization from Pet and also the two implemented interfaces.

Not the answer you're looking for? Browse other questions tagged or ask your own question.