Retreiving Date value through constructor and storing it in variable of type Date. : It throws exception while trying to parse String to Date after getting Date value as a string from the user. 
What should be done in order to store the Date value (or) is there any any specific method to retrieve date.




Medicine.java

package Medicine;
import java.util.Date;

public abstract class Medicine {
	
public int price;
    Date expiryDate;
	
    Medicine() {
    }
	
    Medicine(int price, Date expiryDate) {
	this.price=price;
	this.expiryDate=expiryDate;
	}
	
	public void getDetails() {
	System.out.println("The price is "+this.price);
	System.out.println("The expiry Date for the product is "+this.expiryDate);
    }
	
    abstract void displayLabel();

}
--------------------------------------------------------------------

Tablet.java

    package Medicine;
    import java.util.Date;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;

    public class Tablet extends Medicine{

    Date expDate;
	void displayLabel() {
		System.out.println("Store in a cool and dry place");
	}
	
	Tablet() {
	}
	
	Tablet(int price, Date expDate) {
		this.price=price;
		this.expDate=expDate;
	}
    }
----------------------------------------------------------------------------

Execution Class

int price;

Date expDate=new Date();;

Scanner reader = new Scanner(System.in);

Medicine[] medicineArray =new Medicine[5];

DateFormat df=new SimpleDateFormat("dd-mm-yyyy");

System.out.println("Enter Tablet's price");

price = reader.nextInt();

System.out.println("Enter Tablet's expiry date in yyyy-dd-mm format");

String stringExpDate=reader.nextLine();

		
try {
			expDate=df.parse(stringExpDate);
		
		}
		catch(Exception e){
			System.out.println("Date format not parsed");
		}
		Medicine med1=new Tablet(price,expDate);
		med1.getDetails();
		med1.displayLabel();