Question: Create the AllDayEvent class, a subclass of the Event class to help you store an AllDayEvent. This will keep the Event class functionalities, with one

Create the AllDayEvent class, a subclass of the Event class to help you store an AllDayEvent.
This will keep the Event class functionalities, with one exception:

The constructor will receive the following parameters:
date - String format yyyy-MM-dd is the date when the event occurs;
name - String representing the name of the event;

When we call method EventDuration returns 24.

When we call getStartDate method returns the start date of the event - at 00:00:00.

To solve this problem you can use any class in java.util and java.text

 

import java.text.*;

import java.util.*;

import java.util.concurrent.TimeUnit;

 

class Event{  

private Date startDate, endDate;  

private String name;  

public Event(String startDate, String endDate, String name) {    

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  

try {      

this.startDate= format.parse(startDate);  

this.endDate= format.parse(endDate);   

} catch (Exception e) {   

System.out.println("Data wrong format");   

System.out.println(e.getMessage());  

}   

this.name= name;

}

public Date getStartDate() {  

return startDate;  

}  

public Date getEndDate() {  

return endDate;  

}

public String getName() {    

return name;

}

 // Return the hourly data of an event

public final long eventDuration() {   

long differenceInMs = Math.abs(endDate.getTime() - startDate.getTime());   

return TimeUnit.HOURS.convert(differenceInMs, TimeUnit.MILLISECONDS);  

}

}

// Your class here...

public class prog {  

public static void main(String[] args) throws Exception {    

Event = new AllDayEvent("2019-04-22", "asd");  

System.out.println(e.eventDuration());  // 24 

}

 }




Step by Step Solution

3.50 Rating (150 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Heres the implementation of the AllDayEvent class which is a subclass of the Event class import java... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!