Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, 1st of all I recommend you read a good tutorial / explanation of UML class diagrams, like <a href="http://www.ibm.com/developerworks/rational/library/content/RationalEdge/sep04/bell/" rel="nofollow">this</a> here for example.</p> <p>After you know the basics, it should be easy to translate that into Java code. I'll give you the code for the <code>Universal</code> class and a start for your <code>Vehicle</code>. The rest you'll have to do on your own.</p> <p>The class Universal:</p> <pre><code>public class Universal extends Vehicle { private int trunkSize; public int getTrunkSize() { return this.trunkSize; } public void setTrunkSize(int trunkSize) { this.trunkSize = trunkSize; } } </code></pre> <p>As you can see the first block inside a class box refers to the variables. The <code>-</code> and <code>+</code> indicates the visibility (private for <code>-</code>, public for <code>+</code>). </p> <p>The next block is about the methods, specifying visibility, return type, method name and parameters (type and name).</p> <p>The arrow between <code>Universal</code> and <code>Vehicle</code> indicates a inheritance relationship (see in code that <code>Universal extends Vehicle</code>).</p> <p>So all in all the diagram is a construction plan for your classes; at least for the static part, meaning the relationships and state they can have.</p> <p>The start of class Vehicle:</p> <pre><code>public class Vehicle { private int vehicleNumber; // the rest here ... } </code></pre> <p>Edit: Well, now that I see your code, you seem to have a few misconceptions:</p> <ol> <li><p>The Sedan type is not from type String, it is from type Sedan (which extends Vehicle). Just the new member variable in the Sedan type is of type String, does not matter.</p></li> <li><p>To your 1st question: The <code>Vehicle</code> class is the base (parent) class of <code>Sedan</code>. You do not to do anything with it, inheritance is expressed from the child towards the parent, not the other way around. <code>Vehicle</code> should usually be declared abstract (as you cannot create an instance of a generic <code>Vehicle</code>), but this is not in the diagram.</p></li> <li>To your 2nd question: The <code>has a</code> relationship is just this. It expressed that one class has another class as it's member (which is redundantely expressed inside the class diagram already), so nothing to do for that.</li> </ol> <p>Additionally your code has a few issues:</p> <ol> <li>I do not see any constructors declared in Vehicle class, those 4 can go.</li> <li>Your <code>Sedan</code> has a superflous pair of <code>{}</code> after declaration of your <code>registrationIndex</code> variable.</li> <li>Since your <code>Vehicle</code> has no default constructor, you must call this constructor from your <code>Sedan</code> class (or remove the constructors from <code>Vehicle</code>.</li> <li>Your <code>Universal</code> class calls the <code>Vehicle</code> constructor with the trunkSize while the <code>Vehicle</code> constructor expects the <code>vehicleNumber</code> there.</li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload