Write a method that given an integer array

Assignment Help Data Structure & Algorithms
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.

Verified Expert

The task of the program is to develop 3 java program.The java program is developed to test the sorting of java array using Comparable and comparator interface. To perform this compare() is written.The program is developed using netbeans the code is tested and the screenshot are attached.The code is well commented too.

Reference no: EM132403132

Questions Cloud

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.

Reviews

len2403132

11/19/2019 1:41:40 AM

You must answer a,b,c I do not want just a code question a,b,c must be answers must work in the zip file already with partial code done must be in java must run in intellij idea 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 SongComparatorTest class.

Write a Review

Data Structure & Algorithms Questions & Answers

  Implement an open hash table

In this programming assignment you will implement an open hash table and compare the performance of four hash functions using various prime table sizes.

  Use a search tree to find the solution

Explain how will use a search tree to find the solution.

  How to access virtualised applications through unicore

How to access virtualised applications through UNICORE

  Recursive tree algorithms

Write a recursive function to determine if a binary tree is a binary search tree.

  Determine the mean salary as well as the number of salaries

Determine the mean salary as well as the number of salaries.

  Currency conversion development

Currency Conversion Development

  Cloud computing assignment

WSDL service that receives a request for a stock market quote and returns the quote

  Design a gui and implement tic tac toe game in java

Design a GUI and implement Tic Tac Toe game in java

  Recursive implementation of euclids algorithm

Write a recursive implementation of Euclid's algorithm for finding the greatest common divisor (GCD) of two integers

  Data structures for a single algorithm

Data structures for a single algorithm

  Write the selection sort algorithm

Write the selection sort algorithm

  Design of sample and hold amplifiers for 100 msps by using n

The report is divided into four main parts. The introduction about sample, hold amplifier and design, bootstrap switch design followed by simulation results.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd