Question

In: Computer Science

4) Define an abstract class Name Java class that implements interface Comparable   

4)

Define an abstract class

Name Java class that implements interface Comparable

  

Solutions

Expert Solution

Hi, I hope you are doing well.

4)

Abstract class: Abstract class is defined with the abstract keyword.

Syntax: abstract class B{}  

The abstract class can have both methods abstract as well as non-abstract. An abstract class is needs to be extended and its method needs to be implemented. But it cannot be instantiated. It can have final and static methods also. It can also have constructors too. Final method will force the subclass to not change the body of method. This are the main points to remeber the abstract class.

Comparable interface: The comparable interface is used to order the objects of user defined class(that contains arrays or list ). The comparable interface is found in java.lang package and it only contains one method compareTo(Object).

we can sort the elements of the following type of objects by the comparable insterface:

  • String object
  • Wrapper class object
  • User-defined class object

Related Solutions

In Java: Job class The Job implements the Comparable interface A Job object is instantiated with...
In Java: Job class The Job implements the Comparable interface A Job object is instantiated with three int variables, indicating the arrivalTime, the timeForTheJob, and the priority. When the Job is created it is given the next sequential ID starting from 1. (You should use a static variable to keep track of where you are in ID assignment.) There are also int variables for startTime, waitTime (in queue) and endTime for the Job. The following methods are required: getID, set...
In Java: Job class The Job implements the Comparable interface A Job object is instantiated with...
In Java: Job class The Job implements the Comparable interface A Job object is instantiated with three int variables, indicating the arrivalTime, the timeForTheJob, and the priority. When the Job is created it is given the next sequential ID starting from 1. (You should use a static variable to keep track of where you are in ID assignment.) There are also int variables for startTime, waitTime (in queue) and endTime for the Job. The following methods are required: getID, set...
3.2. Unfortunately, you cannot modify the Rectangle class so that it implements the Comparable interface. The...
3.2. Unfortunately, you cannot modify the Rectangle class so that it implements the Comparable interface. The Rectangle class is part of the standard library, and you cannot modify library classes. Fortunately, there is a second sort method that you can use to sort a list of objects of any class, even if the class doesn't implement the Comparable interface. Comparator<T> comp = . . .; // for example, Comparator<Rectangle> comp = new RectangleComparator(); Collections.sort(list, comp); Comparator is an interface. Therefore,...
JAVA code Create a new class called BetterDiGraph that implements the EditableDiGraph interface See the interface...
JAVA code Create a new class called BetterDiGraph that implements the EditableDiGraph interface See the interface below for details. EditableDigraph below: import java.util.NoSuchElementException; /** * Implements an editable graph with sparse vertex support. * * */ public interface EditableDiGraph {    /** * Adds an edge between two vertices, v and w. If vertices do not exist, * adds them first. * * @param v source vertex * @param w destination vertex */ void addEdge(int v, int w); /** *...
In java design and code a class named comparableTriangle that extends Triangle and implements Comparable. Implement...
In java design and code a class named comparableTriangle that extends Triangle and implements Comparable. Implement the compareTo method to compare the triangles on the basis of similarity. Draw the UML diagram for your classes. Write a Driver class (class which instantiates the comparableTriangle objects) to determine if two instances of ComparableTriangle objects are similar (sample output below). It should prompt the user to enter the 3 sides of each triangle and then display whether or not the are similar...
Define a class of queues that implements the interface QueueInterface, as defined in Listing 7-1 in...
Define a class of queues that implements the interface QueueInterface, as defined in Listing 7-1 in Chapter 7. Use an instance of the class ArrayList to contain a queues entries. Then write a driver/test program adequately demonstrates your new class. Note that you might have to handle exceptions thrown by methods of ArrayList. Deliverables: EmptyQueueException.java (given in Lab_7_StartUp folder) QueueInterface.java (given in Lab_7_StartUp folder) ArrayListQueue.java (need to create) Lab7.java (need to create) QueInterface: @author Frank M. Carrano @author Timothy M....
1. Design a Java CartesianPoint class for a Cartesian Point which implements both cloneable and comparable...
1. Design a Java CartesianPoint class for a Cartesian Point which implements both cloneable and comparable interfaces The class should have the following private member variables: • the x value of a point: int • the y value of a point: int and the class should have the following public member functions: • default constructor which initializes the point to the origin of the Cartesian coordinate system • explicit constructor which initializes the point to a pair of given value...
Write a Java application that implements the following: Create an abstract class called GameTester. The GameTester...
Write a Java application that implements the following: Create an abstract class called GameTester. The GameTester class includes a name for the game tester and a boolean value representing the status (full-time, part-time). Include an abstract method to determine the salary, with full-time game testers getting a base salary of $3000 and part-time game testers getting $20 per hour. Create two subclasses called FullTimeGameTester, PartTimeGameTester. Create a console application that demonstrates how to create objects of both subclasses. Allow the...
Define the classes to complete dynamic array hierarchy with a concrete, abstract and interface class. public...
Define the classes to complete dynamic array hierarchy with a concrete, abstract and interface class. public class DArray { private int array[]; public DArray() { } private void expandArray() { } private void shrinkArray() { } } --------------------------------------------------------------- public abstract class ArrayBP { protected int numElements; protected int numAllocations; public abstract void storeAt(int item, int index) { } public abstract getFrom(int index) { } public abstract int len() { } public abstract void remove();{ } public abstract void removeAt(int index)...
If a class A implements interface I1 and class C and D are derived from class...
If a class A implements interface I1 and class C and D are derived from class A, a variable of type I1 can be used to hold references of what type of objects? which one is correct 1. A, C, and D 2. A and D
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT