How can I get the year from a Date object without using deprecated methods?
<p>I've been given an assignment where I need to create a set of interfaces and classes for a car rental company. I'm busy working on implementing a LicenceNumber class which must match the following spec:</p>
<blockquote>
<p>The licence number has three components. The first component is the concatenation of the initial of the first name of the driver with the initial of the last name of the driver. The second component is the year of issue of the licence. The third component is an arbitrary serial number. For example, the string representation of the licence number for a licence issued to Mark Smith in 1990 would have the form, MS-1990-10, where the 10 is a serial number that, with the initials and year, guarantees the uniqueness of the licence number as a whole.</p>
<p><strong>You should use the java.util.Date class to represent dates. However, you must not use deprecated methods of the Date class. So, for example, in your test classes use java.util.Calendar to construct dates of birth and dates of issue of licences.</strong> You can assume default time zone and locale. (Note, there are now better classes available in the java.time package which was introduced in Java 1.8 but it will be good experience to work with classes
which are written less well).</p>
</blockquote>
<p>So far I've got the following implementation for the LicenceNumber class:</p>
<pre><code>import java.util.Calendar;
import java.util.Date;

public class LicenceNumber {

private String licenceNo;

public LicenceNumber(Name driverName, Date issueDate){
    setLicenceNo(driverName, issueDate);
}

public String getLicenceNo() {
    return licenceNo;
}

public void setLicenceNo(Name driverName, Date issueDate) {
    String initials;
    initials = driverName.getForename().substring(0, 1) + driverName.getSurname().substring(0,1);
    System.out.println(initials);
    int issueYear = issueDate.getYear(); //Deprecated
}
}
</code></pre>
<p>I want to be able to get only the year from issueDate, but the only way I can figure out how to do it, is by using the deprecated method, getYear(). This is obviously against the criteria, so can anyone shed some light on how to get the Year from a Date object without using deprecated methods?</p>
<p>Thanks ahead.</p>