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,...
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....
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
in JAVA PLEASE SHOW OUTPUT! PriorityQueueUserDefinedObjectExample (20) Create an Employee class which implements Comparable<Employee> The constructor...
in JAVA PLEASE SHOW OUTPUT! PriorityQueueUserDefinedObjectExample (20) Create an Employee class which implements Comparable<Employee> The constructor consists of an employee’s first name and an employee’s salary, both of which are instance variables. Create accessor and mutator methods for both of these variables Write an equals method that returns true if the salaries are equal with one cent and the names are exactly equal Write a compareTo method that returns 1 if the salary of this employee is greater than the...
Define a JAVA class ISP. The class consists of the name of the subscription plan and...
Define a JAVA class ISP. The class consists of the name of the subscription plan and a method that display the plan. Derive a class DPlan from ISP. The DPlan will charge RM10 per Mbps subscribe and RM0.20 per GB used. Derive a class MPlan from ISP. The MPlan will charge RM5 per Mbps subscribe and RM0.80 per GB used. Display the plan and select the best plan.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT