90.9k views
1 vote
Find solutions for your homework

Find solutions for your homework

engineeringcomputer sciencecomputer science questions and answerswrite a class named licenseplatewithdate that extends licenseplate. it should add a date field named expirationdate. assume that you have access to the date class from question 4.. it should have the following constructors. they should each invoke a licenseplate constructor: a three argument constructor that accepts displaystring, statestring, and
Question: Write A Class Named LicensePlateWithDate That Extends LicensePlate. It Should Add A Date Field Named ExpirationDate. Assume That You Have Access To The Date Class From Question 4.. It Should Have The Following Constructors. They Should Each Invoke A LicensePlate Constructor: A Three Argument Constructor That Accepts DisplayString, StateString, And
Write a class named LicensePlateWithDate that extends LicensePlate. It should add a Date field named expirationDate. Assume that you have access to the Date class from Question 4..

It should have the following constructors. They should each invoke a LicensePlate constructor:

A three argument constructor that accepts displayString, stateString, and expiration date.

A two argument constructor that accepts a displayString and a stateString. It should make a date with a day and year of 0 for the expiration date.

A one argument constructor that accepts a LicensePlate.

In these constructors, make sure that you never store a Date object that is passed in as a parameter. Store a copy instead.

It should have the following methods:

A setter for expirationDate. This should also store a copy.

A getter for expiration Date.

User Herzult
by
7.6k points

1 Answer

3 votes

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.

User Makerj
by
7.8k points