Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

-----JAVA IMPLEMENTATIONS NEEDED URGENTLY -------- public class Lab01 { private Lab01() { // empty by design } //Ques 8 /** * Compares two Range instances

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

public class Lab01 {

private Lab01() {

// empty by design

}

//Ques 8

/**

* Compares two Range 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 Range that is different

* than the one returned by Range.toString.

*

*

* The returned string has the form "minimum: x, maximum: y" 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 s is the string "abcd"; then:

*

*

* 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

*

*

* @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 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 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:

*

*

* [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

*

*

*

* 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

*

*

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

* may be out of order

*

*/

public static void repair(List 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.

*

*

* 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.

*

*

* For example, if t was the list:

*

*

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

*

*

*

* then splitting t into two sublists yields:

*

*

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

*

*

*

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

* new list:

*

*

* ['a', 'd']

*

*

*

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

* new list:

*

*

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

*

*

*

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

* new list:

*

*

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

*

*

* @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 shuffle(List 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 t) {

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle RMAN For Absolute Beginners

Authors: Darl Kuhn

1st Edition

1484207637, 9781484207635

More Books

Students also viewed these Databases questions