Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't see anywhere in your code where you are calling the setDay, setMonth or setYear methods, so I would expect the call to toUniversalStringTime to always print </p> <pre><code>"The date using a default constructor 111 \n" </code></pre> <p>Then after that call you print it again manually using the values for y, m and d</p> <pre><code>"The date I created is 200056 \n" </code></pre> <p>You need to call the set methods on the d1 object after creation, or pass in the parameters to a constructor to set them, e.g.</p> <pre><code>d1.setYear(y); d1.setMonth(m); d1.setDay(d); </code></pre> <p>but please pay attention to some of the other comments that have been made with regards to refactoring your code, because as has been mentioned, each of your setter methods have fundamental flaws in them that need to be fixed first.</p> <p>Other general notes to your code:</p> <p>In your setYear method you are using the value of y to update the year variable of the object, but in the second if:</p> <pre><code>if (y &gt; 2011) { System.out.println("That year hasn't happened yet!"); y = 2011; } </code></pre> <p>you are actually setting <code>y</code> to 2011 rather than <code>year</code>, so this will have no effect.</p> <p>For some reason in your setMonth method you are not actually setting the month, but you are just validating the value that is passed in, i.e. if the value is not between 1 and 12 you return 1. So the code doesn't match the name of the method and you should change one or the other.</p> <p>Your setDay method is the same as setMonth in that it doesn't actually set the day, just validates it. But what's even worse here is that the call to setDay depends heavily on the month and year already having been set, since you use the <code>month</code> and <code>year</code> variables to determine whether or not the day is valid. This means that setDay must only be called after setMonth and setYear, otherwise you will always default to checking against January 0001 (since month and year are set to 1 by default).</p>
    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.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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