This lab is to test your understanding of a Pairs project and sorting method discussed during...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
This lab is to test your understanding of a Pairs project and sorting method discussed during last week's lectures. The sorting method from the lectures used an array with a type parameter. Given the following Pairable Interface, ComparablePair class, and Tester class, implement a sort method in the Test class that sorts ComparablePair objects. public interface Pairable { public T get First (); public T getSecond(); } public class ComparablePair implements Pairable , Comparable { private T first; private T second; public ComparablePair (T firstItem, T secondItem) { first firstItem; second secondItem; } @Override public T getFirst () { return first; } @Override public T get Second () { return second; } @Override public String toString () { return "(" + first + ", } + second + ")"; @Override public int compareTo (ComparablePair 0) { int first Comparison = this.getFirst().compareTo (o.getFirst()); int secondComparison = this.getSecond ().compareTo (o.getSecond ()); return first Comparison != 0 ? first Comparison secondComparison; import java.util.ArrayList; public class Tester { public static void main (String[] args) { ArrayList listOfStringPairs = new ArrayList (); listOfStringPairs.add (new ComparablePair ("Irene Johnson", "Sandra James")); listOfStringPairs.add(new ComparablePair ("Janet Brown", "Jose Richardson")); listOfString Pairs.add(new ComparablePair ("Norma Powell", "Russell Ramirez")); listofString Pairs.add(new ComparablePair ("Walter Bell", "Kelly Phillips")); listOfStringPairs.add(new ComparablePair ("Norma Powell", "Joe White")); sort (listOfStringPairs); for (ComparablePair stringPair listOfString Pairs) { System.out.println (stringPair); } } // Implement a sort method. public static void sort ( // Your code here. } ) { This lab is to test your understanding of a Pairs project and sorting method discussed during last week's lectures. The sorting method from the lectures used an array with a type parameter. Given the following Pairable Interface, ComparablePair class, and Tester class, implement a sort method in the Test class that sorts ComparablePair objects. public interface Pairable { public T get First (); public T getSecond(); } public class ComparablePair implements Pairable , Comparable { private T first; private T second; public ComparablePair (T firstItem, T secondItem) { first firstItem; second secondItem; } @Override public T getFirst () { return first; } @Override public T get Second () { return second; } @Override public String toString () { return "(" + first + ", } + second + ")"; @Override public int compareTo (ComparablePair 0) { int first Comparison = this.getFirst().compareTo (o.getFirst()); int secondComparison = this.getSecond ().compareTo (o.getSecond ()); return first Comparison != 0 ? first Comparison secondComparison; import java.util.ArrayList; public class Tester { public static void main (String[] args) { ArrayList listOfStringPairs = new ArrayList (); listOfStringPairs.add (new ComparablePair ("Irene Johnson", "Sandra James")); listOfStringPairs.add(new ComparablePair ("Janet Brown", "Jose Richardson")); listOfString Pairs.add(new ComparablePair ("Norma Powell", "Russell Ramirez")); listofString Pairs.add(new ComparablePair ("Walter Bell", "Kelly Phillips")); listOfStringPairs.add(new ComparablePair ("Norma Powell", "Joe White")); sort (listOfStringPairs); for (ComparablePair stringPair listOfString Pairs) { System.out.println (stringPair); } } // Implement a sort method. public static void sort ( // Your code here. } ) {
Expert Answer:
Answer rating: 100% (QA)
The correct answer option is to implement the sort method in the Tester class that sorts the Compara... View the full answer
Related Book For
Concepts in Enterprise Resource Planning
ISBN: 978-1111820398
4th edition
Authors: Ellen Monk, Bret Wagner
Posted Date:
Students also viewed these operating system questions
-
Would you make any changes to the Federal tax policy related to this area of the IRC ? If so , what would you change and why? How would these changes help rectify the disparate outcomes by race?
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
The acquisition committee of KE plc is considering making takeover bids for two competitors, Scot plc, a listed company, and Ring Ltd. Summarised financial data is given below for these companies....
-
Hankla Company plans to purchase either (1) zero-coupon bonds that have ten years to maturity, a par value of $100 million, and a purchase price of $40 million, or (2) bonds with similar default risk...
-
The accountant of Cornett Chocolates Ltd., Maria Fraulein, has been advised by her auditors that the companys investment in Concertinas Milk Ltd. should be accounted for using the equity method of...
-
These data consist of the 503 daily returns for the calendar years 2005 and 2006 of the S\&P value-weighted index. (The data file contains additional years - this exercise uses only 2005 and 2006...
-
Segmental Disclosures In the Appendix to this chapter, the partial segmental disclosures for General Electric (GE) are provided. 1. How does GE organize and present its segment data? 2. Compute the...
-
Writing a proposal for cryptocurrency usage in retail industry. Can anyone please suggest me some good resources...what sort of research studies i have to perform for my dissertation. Is explorative...
-
On January 1, Year 2, PAT Ltd. acquired 90% of SAT Inc. when SAT's retained earnings were $1,000,000. There was no acquisition differential. PAT accounts for its investment under the cost method. SAT...
-
The Crime Scene: Field Notes, Documenting, and Reporting based on the lecture and text. This assignment will give employees an opportunity to actively engage in a discussion with classmates about...
-
Describe the impact of a firms pricing structure on its business model.
-
Write a mission statement for 99designs, the company highlighted in the Partnering for Success feature. How can this statement help clarify and direct the core strategy component of 99designs...
-
What are the two primary functions of the financial management of a firm?
-
Early in the chapter, under the section titled Creating a New Venture Team, a quote is provided that reads as follows: People are the one factor in production ... that animates all others. In the...
-
Define networking. Why is it important for an entrepreneur to have a vibrant social and professional network?
-
"When I have time, I don't have money. When I have money, I don't have time," says Glenn Kelman, Redfin CEO. He's not alone. While many workers find themselves faced with 60-, 70-, or 80-hour weeks...
-
Complete problem P10-21 using ASPE. Data from P10-21 Original cost ................................................................. $7,000,000 Accumulated depreciation...
-
Suppose you are a manager of Fitters Accounting and Finance department. What human resources information do you think you would need to effectively manage your Accounting and Finance employees?
-
Using the Internet, research your states regulations for employing teenagers - such as minimum age of employment. Do the same for a neighboring state. Are the two state regulations the same? Why...
-
What are potential sources of risk in Fitters supply chain? How should Fitter prepare to minimize these risks? Research this topic on the Internet, and use examples to support your reasoning.
-
Identical positively charged objects \(A, B\), and \(C\) are launched with the same initial speed from the same position above a negatively charged sheet that produces a uniform electric field. The...
-
A proton, a deuteron (a hydrogen nucleus containing one proton and one neutron), and an alpha particle (a helium nucleus consisting of two protons and two neutrons) initially at rest are all...
-
What orientation of an electric dipole in a uniform electric field has the greatest electric potential energy? What orientation has the least? (Let the system comprise both the electric dipole and...
Study smarter with the SolutionInn App