Define Class Event
Define Class Event
Example Input/Output 1:
Input:
5
TreasureHunt 200 60
ProjectExpo 500 180
RapidFireQuiz 200 20
PaperPresentation 400 120
Hackathon 500 180
Output:
RapidFireQuiz 200 20
TreasureHunt 200 60
PaperPresentation 400 120
Hackathon 500 180
ProjectExpo 500 180
Exaplanation:
Here N = 5.
After sorting the events based on the given conditions, the events become
RapidFireQuiz 200 20
TreasureHunt 200 60
PaperPresentation 400 120
Hackathon 500 180
ProjectExpo 500 180
Example Input/Output 2:
Input:
6
ProjectExpo 800 180
TreasureHunt 100 90
Hackathon 800 240
TechQuiz 100 30
HexCoding 800 180
PaperPresentation 800 180
Output:
TechQuiz 100 30
TreasureHunt 100 90
HexCoding 800 180
PaperPresentation 800 180
ProjectExpo 800 180
Hackathon 800 240
CODE SNIPPET:
class Event implements Comparable<Event>
{
private String title="";
private int registrationFee,duration;
public Event(String title,int registration,int duration)
{
this.title=title;
this.registrationFee=registration;
this.duration=duration;
}
@Override
public String toString()
{
return this.title+' '+this.registrationFee+' '+this.duration;
}
@Override
public int compareTo(Event e)
{
if(this.registrationFee==e.registrationFee)
{
if(this.duration==e.duration)
{
return this.title.compareTo(e.title);
}
return this.duration-e.duration;
}
return this.registrationFee-e.registrationFee;
}
}
how to follow this blog bro
ReplyDelete