Answer:
public class LicensePlateWithDate extends LicensePlate {
private Date expirationDate;
public LicensePlateWithDate(String displayString, String stateString, Date expirationDate) {
super(displayString, stateString);
this.expirationDate = new Date(expirationDate);
}
public LicensePlateWithDate(String displayString, String stateString) {
super(displayString, stateString);
this.expirationDate = new Date(0, 0);
}
public LicensePlateWithDate(LicensePlate licensePlate) {
super(licensePlate);
this.expirationDate = new Date(0, 0);
}
public void setExpirationDate(Date expirationDate) {
this.expirationDate = new Date(expirationDate);
}
public Date getExpirationDate() {
return new Date(expirationDate);
}
}
Step-by-step explanation:
- The `LicensePlateWithDate` class extends the `LicensePlate` class and adds the `expirationDate` field of type `Date`.
- The three-argument constructor accepts the `displayString`, `stateString`, and `expirationDate` as parameters. It invokes the `LicensePlate` constructor using the `super()` keyword to initialize the `displayString` and `stateString` fields. The `expirationDate` is stored as a copy.
- The two-argument constructor accepts the `displayString` and `stateString` parameters. It invokes the `LicensePlate` constructor using the `super()` keyword and sets the `expirationDate` to a new `Date` object with day and year set to 0.
- The one-argument constructor accepts a `LicensePlate` object and invokes the `LicensePlate` constructor using the `super()` keyword. It sets the `expirationDate` to a new `Date` object with day and year set to 0.
- The `setExpirationDate()` method sets the `expirationDate` field to a copy of the provided `expirationDate`.
- The `getExpirationDate()` method returns a copy of the `expirationDate` field to ensure encapsulation.