Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Beginning Java
Getting error of your class is not abstract to override the compareTo method
Likhitha Veshala
Greenhorn
Posts: 4
posted 11 months ago
Number of slices to send:
Optional 'thank-you' note:
Send
Purpose: Sorting a collection
In this program I made all it correctly by exploring more but still getting the same error.
Can anyone figure out what's going wrong
Thanks in Advance!
public class Pair implements Comparable<Pair>{ int startdate; int enddate; public Pair(int startdate,int enddate){ this.startdate=startdate; this.enddate=enddate; } // @Override public int CompareTo(Pair that){ if(this.enddate > that.enddate){ return 1; }else{ return -1; } } } class Solution { public int maxEvents(int[][] events) { int n=events.length; List<Pair> list = new ArrayList<>(); for(int i=0;i<n;i++){ int start = events[i][0]; int end = events[i][1]; list.add(new Pair(start,end)); } Collections.sort(list); for(Pair p : list){ System.out.println(p.startdate+" "+p.enddate); } return 1; } }
Piet Souris
Bartender
Posts: 5465
212
posted 11 months ago
1
Number of slices to send:
Optional 'thank-you' note:
Send
hi Likhitha,
welcome to the Ranch and enjoy the stay!
The method to override is compareTo, not CompareTo.
By the way: what if the enddates are equal?
There are three kinds of actuaries: those who can count, and those who can't.
Likhitha Veshala
Greenhorn
Posts: 4
posted 11 months ago
1
Number of slices to send:
Optional 'thank-you' note:
Send
Oops.. that's the silly mistake done by me:)
Thank you for catching up.
And if the enddates are equal.., then I will see the startdate it should be sorted according to the startdate then.
// @Override public int compareTo(Pair that){ if(this.enddate > that.enddate){ return 1; }else if(this.enddate < that.enddate){ return -1; }else{ return this.startdate-that.startdate; } }
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
How to use a while loop to return the appointments for the next seven days.
Data table displaying same item multiple times-not supposed to
Resultset.getdate problem...
Cannot convert 4/21/16 12:00 AM of type class java.util.Date to class java.sql.Date
Why does EJB assume a join table and how do i get around it?
More...