9.1. Exercise 1 Consider the generic interface Pair: public interface Pairck, V> { public K getkey(); public V getValue(); Write a class SuccessivePair implementing the Pair interface. The class has two instance variables which are predecessor (of type K) and successor (of type V). Define the constructor of the class SuccessivePair that initializes the instance variables. 9.2. Exercise 2 In a class named Util, define a generic method, areSuccssive, which takes two objects of the same type implementing Comparable interface. Based on compareto method, areSuccssive returns true if the first precede the second with exactly 1 (value returned by compareTo is -1), otherwise, it returns false. Test your areSuccssive method. Examples: SuccessivePaircstring, String> pl = new SuccessivePairc> ("Apple", "Banana"); SuccessivePaircstring, String> p4 = new SuccessivePairco("Orange", "Kiwi"); Util.areSuccessive(p1.getkey(), p1.getValue()); // will return true Util.areSuccessive(p4.getkey(), p4.getValue()); // will return false

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

USING JAVA

INCLUDE EXPLANATION IF POSSIBLE

9.3. Exercise 3
In the class named Util, overload the generic method, areSuccssive, which takes
two objects of type SuccessivePair<T, T>, where T implements Comparable<T>
interface. Two objects of type SuccessivePair<T, T> are considered successive if
the value of the first precede the key of the second (use areSuccssive from the
Exercise 2).
Test your new areSuccssive method.
Examples:
SuccessivePair<String, String> pl = new SuccessivePairc>("Apple", "Banana");
SuccessivePair<String, String> p2 = new SuccessivePair<>("Cherry", "Dates");
SuccessivePaircstring, String> p3=new SuccessivePairc>("Elderberry", "Fig");
Util.areSuccessive(p1, p2); // will return true
Util.areSuccessive(p2, p3); // will return true
Util.areSuccessive(p1, p3); // will return false
Transcribed Image Text:9.3. Exercise 3 In the class named Util, overload the generic method, areSuccssive, which takes two objects of type SuccessivePair<T, T>, where T implements Comparable<T> interface. Two objects of type SuccessivePair<T, T> are considered successive if the value of the first precede the key of the second (use areSuccssive from the Exercise 2). Test your new areSuccssive method. Examples: SuccessivePair<String, String> pl = new SuccessivePairc>("Apple", "Banana"); SuccessivePair<String, String> p2 = new SuccessivePair<>("Cherry", "Dates"); SuccessivePaircstring, String> p3=new SuccessivePairc>("Elderberry", "Fig"); Util.areSuccessive(p1, p2); // will return true Util.areSuccessive(p2, p3); // will return true Util.areSuccessive(p1, p3); // will return false
9.1. Exercise 1
Consider the generic interface Pair:
public interface Pairck, V> {
public K getkey();
public V getvalue();
}
Write a class SuccessivePair implementing the Pair interface. The class has two
instance variables which are predecessor (of type K) and successor (of type V). Define
the constructor of the class SuccessivePair that initializes the instance variables.
9.2. Exercise 2
In a class named Util, define a generic method, areSuccssive, which takes two
objects of the same type implementing ComparableT> interface. Based on
compareto method, areSuccssive returns true if the first precede the second with
exactly 1 (value returned by compareTo is -1), otherwise, it returns false.
Test your areSuccssive method.
Examples:
SuccessivePair<String, String> pl = new SuccessivePair<>("Apple", "Banana");
SuccessivePair<String, String> p4 = new SuccessivePair<>("Orange", "Kiwi");
Util.areSuccessive(p1.getkey(), p1.getValue()); // will return true
Util.areSuccessive(p4.getkey(), p4.getValue()); // will return false
Transcribed Image Text:9.1. Exercise 1 Consider the generic interface Pair: public interface Pairck, V> { public K getkey(); public V getvalue(); } Write a class SuccessivePair implementing the Pair interface. The class has two instance variables which are predecessor (of type K) and successor (of type V). Define the constructor of the class SuccessivePair that initializes the instance variables. 9.2. Exercise 2 In a class named Util, define a generic method, areSuccssive, which takes two objects of the same type implementing ComparableT> interface. Based on compareto method, areSuccssive returns true if the first precede the second with exactly 1 (value returned by compareTo is -1), otherwise, it returns false. Test your areSuccssive method. Examples: SuccessivePair<String, String> pl = new SuccessivePair<>("Apple", "Banana"); SuccessivePair<String, String> p4 = new SuccessivePair<>("Orange", "Kiwi"); Util.areSuccessive(p1.getkey(), p1.getValue()); // will return true Util.areSuccessive(p4.getkey(), p4.getValue()); // will return false
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY