Interface:
Interface is a reference type in Java, which contains a collection of abstract methods.
An interface needs to the follow certain conditions such as:
- One cannot instantiate an interface.
- Interfaces do not contain any constructors.
- All methods present in the interface are abstracts.
- An interface does not contain any instance field.
- An interface cannot be extended by a class.
Comparable Interface:
A comparable interface is a generic interface that defines the compareTo() method that is used for comparing objects.
Example:
//java langauage package for comaprable interface
package java.lang
//comparable interface definition
public interface Comparable <E>
{
//use of compareTo to compare objects
public integer compareTo(E o);
}
The compareTo() method determines the order of this object with the specified object “o” and returns a negative integer, zero or positive integer, if this object is less than, equal to or greater than object “o”.
Want to see the full answer?
Check out a sample textbook solutionChapter 13 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
- 1. Why do you need to implement all the methods of an interface in class which implements an interface?arrow_forwardPart 2: Sorting the WorkOrders via dates Another error that will still be showing is that there is not Comparable/compareTo() method setup on the WorkOrder class file. That is something you need to fix and code. Implement the use of the Comparable interface and add the compareTo() method to the WorkOrder class. The compareTo() method will take a little work here. We are going to compare via the date of the work order. The dates of the WorkOrder are saved in a MM-DD-YYYY format. There is a dash '-' in between each part of the date. You will need to split both the current object's date and the date sent through the compareTo() parameters. You will have three things to compare against. You first need to check the year. If the years are the same value then you need to go another step to check the months, otherwise you compare them with less than or greater than and return the corresponding value. If you have to check the months it would be the same for years. If the months are the same you…arrow_forwardImplement the following parking permit class using java It has a dependency on the car class, no need to implement the car class. Use the diagram for refrencearrow_forward
- You have to implement program that compares graduate students based on their ranks. The design of the program is given in the following UML diagram: • Student class: Base class that GradStudent extends. • GradStudent class: The objects from this class will be used for comparisons. • Rankable interface: Defines the implementation needed for comparison. GradStudent implements this interface. • Test class will be used to get student information from the user and demonstrate the comparison of students.arrow_forwardFor a class they are developing jointly, Sally and Harry construct two separate compareTo methods. Depending on the connection between two objects, Sally's compareTo method returns -1, 0 or +1. The results of Harry's compareTo technique are -6, 0 or +3. Which approach is best?arrow_forwardThis assignment is supposed to represent a group of students in a course. A group of students in a course will be assigned an assignment and produce a collection of assignment results. The results will be used to figure out grade statistics. The grade they receive for their work on the assignment is entirely dependant on the student's energy level. If the student works on many assignments without sleeping their grade will suffer. You will implement four classes (Assignment, AssignmentResult, Student, and Course), they will depend on each other in the order they are listed. Hint: Work on the methods in the order they are found in the documentation below, implement the getter and setter methods before the more complicated methods. Work on the Assignment class, AssignmentResult class, Student class and Course class in that order. Make sure you don't name your class variables the same name as you class's methods. In other words if you have method named id you cannot have a class…arrow_forward
- Program thisarrow_forwardCreate a deck of cards class. Internally, the deck of cards should use another class, a card class. Your requirements are: The Deck class should have a deal method to deal a single card from the deck After a card is dealt, it is removed from the deck. There should be a shuffle method which makes sure the deck of cards has all 52 cards and then rearranges them randomly. The Card class should have a suit (Hearts, Diamonds, Clubs, Spades) and a value (A,2,3,4,5,6,7,8,9,10,J,Q,K)arrow_forwardT/F1. Interface classes cannot be extended but classes that implement interfaces can be extended.arrow_forward
- Identify the steps need to be taken in the correct orderarrow_forwardWhy is it important for a class to have a destructor implemented? With your comment, fill in the spaces.arrow_forwardExplain the advantages of passing this data to a method rather than the current class object directly.arrow_forward
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,