Reference no: EM132403132
Exercise
Resolve the following questions:
a) Write a method (you don't need to implement it) that, given an integer array (int []) it is returned in ascending order. You should look into the methods that the Arrays class provides.
b) In Java, the natural order of the objects is defined by the Comparable interface. When an object implements such interface, you can use the compare To method to determine whether an object a is less than, equal, or greater than another object b:
If the result of a.compareTo (b) is negative, then it means a < b
If the result is zero, then it means a = b (equals should return true as well) It the result is positive, then a > b
The Comparable interface is used by the sorting algorithms implemented in Java. Fill in the compare To method in the Song class following the criteria you will find in the comments above the method. After that, you can execute the tests that you can find in the SongCompareTest class. (Hint: in order to sort String objects in lexicographic order you may need to ignore case).
c) Sometimes we may need to sort an object by multiple criteria, apart from the compare To order. In Java you can do this by implementing the Comparator interface. We can create multiple sort criteria for a T class implementing classes that implement Comparator<T>. For instance, we could create a class that instead of sorting integers in their natural order, it sorts them depending on the number of divisors they have.
To compare using this class, we use the compare method, which behaves similarly to compareTo (< 0 if a < b, > 0 if a > b, and 0 if a = b).
The sorting methods implemented in Java also allow using an object from the Comparator class as additional parameter to set a different order as the one provided by Comparable.
In this exercise you will have to implement a sort filter which sorts songs by title and author. You will have to modify the code in the TitleAndAuthorFilter class (edu.uoc.mecm.eda.potify.filters). You can find the matching tests in the Son gComparatorTest class.
What is the present value of the lottery
: A.) What is the present value of the lottery? B.) How much interest is earned on the present value to make the $2 million-per-year payment?
|
What is the price of a preferred stock
: What is the price of a preferred stock bought to yield 5% annually, if it pays level dividends of $40 semiannually, and the next dividend is due in exactly
|
What are the options for the city
: What are the options for the city/county/state financing of small sporting stadium in Richmond Virginia? Which options would you recommend to the city/county
|
Underlying free speech vs. censorship debate in cyberspace
: Describe some of the issues underlying the free speech vs. censorship debate in cyberspace. What is meant by "free speech"?
|
Write a method that given an integer array
: Write a method that given an integer array - determine whether an object a is less than, equal, or greater than another - Comparable interface
|
Why do we need an automated tool for sql injection
: Write an essay discussing sqlmap, an automated tool for sql injection and database takeover. Why do we need an automated tool for sql injection?
|
Was the study experimental or observational
: Was the study experimental or observational? Was the data collected cross-sectional or time series? Are the study data Ratio or Interval, Ordinal or Nomal?
|
How the article relates to the selected chapter key term
: Using 300-350 words, write a brief discussion, in your own words of how the article relates to the selected chapter Key Term. A discussion is not rehashing.
|
Show the depreciation and remaining book value
: EGR 310- An asset was purchased for $100,000. It has a 5 year life. The asset is expected to have a salvage value of $10,000 after the five years.
|