Question
Implement all the method bodies using JAVA.
Collection Selector Problem Overview This assignment focuses on implementing the methods of a class much like java.util.collections. The Selector java file defines a class with static methods that implement polymorphic algorithms that operate on and/or return Collections. Each method of Selector is very clearly specified, is independent of the other methods in the class, and is designed to provide relatively simple functionality. So, this is a great context for practicing what weve been discussing in lecture - generalized programming and test-based verification The Selector class You must correctly implement all the method bodies of the provided Selector class. Your implementation must adhere eractly to the API of the Selector class, as described in the provided source code comments and as described below. public class Selector ( public static <T> T min (Collection<Tc, Comparator<T comp) public static <T> T max (Collection<T> c, Comparator<T> comp) public static T kmin(Collection<T> c, int k, Comparatort> comp) public static <T> T kmax (CollectioncT> c, int k, Comparator<T> comp) public static T CollectionT range (Collection<T c, T lox, T high, Comparator<T> comp) public static <T> T ceiling(Collection<T> c, T key, ComparatorT> comp) public static <T> T floor (CollectionT> c,T key, Comparator<T> comp) The sections that follow provide details of each methods behavior as well as specific examples. The min method. This method selects the minimum value from a given collection, as defined by a given comparator. If either the collection or comparator is null, this method throws an IllegalArgument Exception. If the collection is empty, the method throws a NoSuchElement Exception. The collection must not be changed by this method. Examples T min(c, comp) comp Integer Integer Integer (String, Integer) [(A,5), (B,4), (C,3), (D,2), (E, 1)] ascending by String field (A.5) (String, Integer) I(A,5), (B,4), (C,3), (D,2), (E, 1)] ascending by Integer feld (E,1) [2, 8, 7, 3, 4] [8, 7, 6, 5, 4 ascending order descending order ascending order 9
media%2F390%2F3902a25c-7e2e-4773-ba44-1f
media%2F762%2F76247c80-9c8f-4125-a53b-3a
media%2F114%2F114b1c7f-3d7d-4c53-a53a-a9
0 0
Add a comment Improve this question Transcribed image text
Answer #1

package com.javacodegeeks.corejava.util;

import java.util.ArrayList;

import java.util.Collections;

import java.util.List;

public class MyCollectionsExample {

public static void main(String[] args) {

List<Double> temperatureList = new ArrayList<Double>();

temperatureList.add(33.9);

temperatureList.add(37.8);

temperatureList.add(40.5);

temperatureList.add(15.3);

temperatureList.add(25.6);

// Print elements of temperatureList

System.out.println(temperatureList);

//Get maximum temperature from temperatureList

Double max = Collections.max(temperatureList);

System.out.println("Maximun temperature: "+max);

//Get minimum temperature from temperatureList

Double min = Collections.min(temperatureList);

System.out.println("Minimum temperature: "+min);

//Reverse the list

Collections.reverse(temperatureList);

System.out.println("Reversed List: "+temperatureList);

//Copy elements from one list to another

List<Double> temperatureList = new ArrayList<Double>(temperatureList.size());

newTemperatureList.add(13.6);

newTemperatureList.add(10.2);

newTemperatureList.add(42.9);

newTemperatureList.add(34.4);

newTemperatureList.add(27.2);

System.out.println("New temperature list: "+newTemperatureList);

Collections.copy(newTemperatureList, temperatureList);

System.out.println("New temperature list after copy: "+newTemperatureList);

  

Collections.replaceAll(temperatureList, 40.5, 0.0);

System.out.println("After replaceAll: "+temperatureList);

}

}

Add a comment
Know the answer?
Add Answer to:
Implement all the method bodies using JAVA. Collection Selector Problem Overview This assignment focuses on implementing...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVA Question a) Write a generic method public static <...> Collection<Pair<...>> sortPairCollection(Collection <Pair<....>> col) in a...

    JAVA Question a) Write a generic method public static <...> Collection<Pair<...>> sortPairCollection(Collection <Pair<....>> col) in a Utils class that takes as parameter a collection of Pair<K,V> objects and returns a new collection object (use ArrayList<...>) with the pair elements from collection col sorted in ascending order. For comparing pairs, the K type must implement Comparable<....> Use the proper type constraints. b) Write a main() function in Utils.java that tests the sortPairCollection() with K=String and V=Integer.

  • this is a generic class in java how implement sort method   public class ArrayBag<T> {   ...

    this is a generic class in java how implement sort method   public class ArrayBag<T> {    private T[] data;    private int manyItems; // TODO change and implement this method to use the generic type    // Sort the elements based on the comparator passed to this method    // You must use Selection Sort algorithm    public void sort(Comparator<T> comp) {                     } }

  • Java implement the method in IteratorExercise.java using only list iterator methods: bubbleSort: sort the provided list...

    Java implement the method in IteratorExercise.java using only list iterator methods: bubbleSort: sort the provided list using bubble sort Do not modify the test code in each function. You can look at that code for some ideas for implementing the methods. import java.lang.Comparable; import java.util.*; public class IteratorExercise {       public static <E extends Comparable<? super E>> void bubbleSort(List<E> c) throws Exception {        // first line to start you off        ListIterator<E> iit = c.listIterator(), jit;...

  • Java, can you help me out thanks. CSCI 2120 Introduction For this assignment you will implement...

    Java, can you help me out thanks. CSCI 2120 Introduction For this assignment you will implement two recursive methods and write JUnit tests for each one. You may write all three methods in the same class file. You are required to write Javadoc-style documentation for all of your methods, including the test methods. Procedure 1) Write method!! a recursive method to compare two Strings using alphabetical order as the natural order (case insensitive, DO NOT use the String class built-in...

  • 1 Overview For this assignment you are required to write a Java program that plays (n,...

    1 Overview For this assignment you are required to write a Java program that plays (n, k)-tic-tac-toe; (n, k)-tic- tac-toe is played on a board of size n x n and to win the game a player needs to put k symbols on adjacent positions of the same row, column, or diagonal. The program will play against a human opponent. You will be given code for displaying the gameboard on the screen. 2 The Algorithm for Playing (n, k)-Tic-Tac-Toe The...

  • 1. Do the following a. Write a class Student that has the following attributes: - name:...

    1. Do the following a. Write a class Student that has the following attributes: - name: String, the student's name ("Last, First" format) - enrollment date (a Date object) The Student class provides a constructor that saves the student's name and enrollment date. Student(String name, Date whenEnrolled) The Student class provides accessors for the name and enrollment date. Make sure the class is immutable. Be careful with that Date field -- remember what to do when sharing mutable instance variables...

  • Recursively sorting an unbounded stack (java) in ascending order? (This assignment is only limited to stacks...

    Recursively sorting an unbounded stack (java) in ascending order? (This assignment is only limited to stacks only, No other data structures are allowed) My professor gave us a hint on how to implement this, however she wants the comparable interface to be used. im not sure on how to do this. Hint: May want to use a public method that accepts the original stack and then creates the two additional stacks needed. This method then calls a private method that...

  • Write in Java Implement the parse method and test it by calling with three different strings...

    Write in Java Implement the parse method and test it by calling with three different strings and by printing the results. The Scanner method can be used to read values from strings, files, or System.in. We need to invoke the useDelimiter method to define what symbols can separate, or terminate, the digits of a Fraction. public static Fraction parse(String input) t Scanner s new Scanner(input) useDelimitercTVMitln"); int num s.nextlnt() int denom s.nextlnt); s.close): return new Fraction(num, denom) class Codechef static...

  • Implement a method to build an AVL tree out of a sorted (ascending order) array of...

    Implement a method to build an AVL tree out of a sorted (ascending order) array of unique integers, with the fastest possible big O running time. You may implement private helper methods as necessary. If your code builds a tree that is other than an AVL tree, you will not get any credit. If your code builds an AVL tree, but is not the fastest big O implementation, you will get at most 12 points. You may use any of...

  • The task of this project is to implement in Java Hash Table structure using Linear Probing...

    The task of this project is to implement in Java Hash Table structure using Linear Probing Collision Strategy.   You can assume that no duplicates or allowed and perform lazy deletion (similar to BST). Specification Create a generic class called HashTableLinearProbe <K,V>, where K is the key and V is the value. It should contain a private static class, HashEntry<K,V>. Use this class to create array to represent Hashtable:             HashEntry<K,V> hashtable[]; Implement all methods listed below and test each method...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT