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

  Define second largest element in a sequence of n elements

Devise an efficient algorithm for finding the second largest element in a sequence of n elements and determine the worst-case complexity of your algorithm.

  Give an algorithm that takes n lines as input

Give an algorithm that takes n lines as input and in O(n log n) time returns all of the ones that are visible. Figure 5.10 gives an example

  Design and develop algorithms using pseudocode

SIT105 - Thinking Technology and Design Assignment - Applied Project, Deakin University, Australia. Design and develop algorithms using pseudocode

  What is algorithm what is algorithm

What is Algorithm? What is Algorithm? What is Algorithm? What is Algorithm? What is Algorithm? What is Algorithm?

  Give the preorder traversal

Orange, pink, green, purple, blue, green, red, emerald, teal, clear. black, violet, maroon, yellow, white .Put the data into a binary search tree .

  Describe the base case of a recursive algorithm

Which of the following statements could describe the base case of a recursive algorithm? You are using a language that does not support recursion. What data structure would you use to traverse a binary search tree in order

  Write an algorithm that converts a decimal number

Write an algorithm that converts a decimal number between 0 and 15 into its 4 bit unsigned binary representation.

  Explain in words a linear-time algorithm

The max subsequence product problem for an array a = a1,a2,...,an of integers is the problem of determining the largest product E(summation)k=1(bottom) j(top) ak formed by a subsequence of a.

  Deleting a random element from an arraylist

In the archive, you will find the RandomQueue class, which implements the Queue interface in a way that, when we call remove()/poll(), a random element is removed from the queue. Currently, this is done by storing all the elements in an ArrayList ..

  Prepare a currency conversion design

currency conversion design pseudocodeprogram pseudocodestart main moduledeclare option 0declare value 0declare

  Create a default and parameterized constructor

Create a default and parameterized constructor. Create sets/gets for all instance variables. Create a get method to calculate and return the profit or loss. This would be calculated as Number of shares * (current price - purchase price).

  Question 1a explain the meaning of each of the following

question 1a explain the meaning of each of the following pointer declarations-i float a -0.137float pa ampaii double

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