1. Engineering
  2. Computer Science
  3. java implementations needed urgently public class lab01 private...

Question: java implementations needed urgently public class lab01 private...

Question details

-----JAVA IMPLEMENTATIONS NEEDED URGENTLY --------

public class Lab01 {

private Lab01() {

// empty by design

}

//Ques 8

/**

* Compares two <code>Range</code> instances by their widths.

*

* @param r1

* a Range

* @param r2

* a second Range

* @return the value 0 if both Range instances are equal; -1 if r1 is narrower

* than r2; and 1 if r1 is wider than r2

*/

public static int compareTo(Range r1, Range r2) {

return 0;

}

//Ques 9

/**

* Returns a string representation of a <code>Range</code> that is different

* than the one returned by <code>Range.toString</code>.

*

* <p>

* The returned string has the form <code>"minimum: x, maximum: y"</code> where

* x is the minimum value of the range and y is the maximum value of the range.

*

* @param r

* a Range instance

* @return a string representation of the range

*/

public static String toString(Range r) {

return false;

}

  

//Ques 10

/**

* Returns the character n positions from the end of the string s. For example,

* suppose <code>s</code> is the string <code>"abcd"</code>; then:

*

* <pre>

* Lab1.charFromEnd(s, 0) returns 'd'

* Lab1.charFromEnd(s, 1) returns 'c'

* Lab1.charFromEnd(s, 2) returns 'b'

* Lab1.charFromEnd(s, 3) returns 'a'

* Lab1.charFromEnd(s, 4) throws an IllegalArgumentException

* Lab1.charFromEnd(s, -1) throws an IllegalArgumentException

* </pre>

*

* @param s

* a string of length 1 or greater

* @param n

* the desired location of the character counting from the end of the

* string

* @return the character located n positions from the end of the string

* @throws IllegalArgumentException

* if the character located n positions from the end of the string

* does not exist

*/

public static char charFromEnd(String s, int n) {

return 0;

}

//Ques 11

/**

* Sorts a list of three integers so that the elements are in descending order

* (largest to smallest). The size of the list remains unchanged.

*

* @param t

* a list

* @throws IllegalArgumentException

* if the size of list is not equal to 3

*/

public static void sort2(List<Integer> t) {

}

//Ques 12

/**

* Returns the number of strings in the list t that are equal to the target

* string.

*

* @param t

* the list to search

* @param target

* the string to search for

* @return the number of strings in the list t that are equal to target

*/

public static int frequency(List<String> t, String target) {

return 0;

}

//Ques 13

/**

* Sorts the elements of the list t so that the elements are in ascending order.

* A precondition of this method is that t must be already sorted in ascending

* order except that adjacent pairs of elements in t may be out of order.

* Consider the following almost sorted lists:

*

* <pre>

* [1, 0] 1, 0 is out of order

* [0, 2, 1] 2, 1 is out of order

* [0, 2, 1, 3] 2, 1 is out of order

* [0, 2, 1, 4, 3] 2, 1 and 4, 3 are out of order

* [0, 1, 3, 2, 4] 3, 2 is out of order

* </pre>

*

* <p>

* This method switches the positions of the out-of-order adjacent elements thus

* repairing the list so that it is in sorted order.

*

* @param t

* a list of almost sorted elements

*

* <pre>

* t is sorted in ascending order except that adjacent pairs of elements

* may be out of order

* </pre>

*/

public static void repair(List<Integer> t) {

// if the list has less than 2 elements then is already sorted

}

//Ques 14

/**

* Returns a new list of characters formed by shuffling the

* characters of the given list. It is a precondition that

* the given list t contains at least two elements, and that

* the number of elements is an even number. The list is not

* modified by this method.

*

* <p>

* To shuffle the characters in t, imagine splitting the list

* t in half so that the first (n / 2) characters of t are in

* one sublist, and the remaining (n / 2) characters of t are

* in the second sublist. The new returned list is formed by

* adding the first character of the first sublist to the

* new list, then adding the first character of the second sublist,

* then adding the second character of the first sublist, then

* adding the second character of the second sublist, and so on,

* until all of the characters in the two sublists are added

* to the new list.

*

* <p>

* For example, if t was the list:

*

* <pre>

* ['a', 'b', 'c', 'd', 'e', 'f']

* </pre>

*

* <p>

* then splitting t into two sublists yields:

*

* <pre>

* ['a', 'b', 'c'] and ['d', 'e', 'f']

* </pre>

*

* <p>

* Take the first two characters of each sublist and add them to the

* new list:

*

* <pre>

* ['a', 'd']

* </pre>

*

* <p>

* Then take the next two characters of each sublist and add them to the

* new list:

*

* <pre>

* ['a', 'd', 'b', 'e']

* </pre>

*

* <p>

* Then take the next two characters of each sublist and add them to the

* new list:

*

* <pre>

* ['a', 'd', 'b', 'e', 'c', 'f']

* </pre>

*

* @param t a non-null list of characters

* @return a new list equal to the shuffle of the characters in t

* @pre. t is not null

* @pre. t.size() is greater than or equal to 2

* @pre. t.size() is an even number

*/

public static List<Character> shuffle(List<Character> t) {

}

//Ques 15

  

/**

   * Replaces the elements of a list of angles in degrees with the equivalent

   * angles in radians. The size of the list remains unchanged.

   *

   * @param t

   * a list of angles in degrees

   */

public static void toRadians(List<Double> t) {

  

}

}

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution