package eecs2030.test2; import java.util.ArrayList; import java.util.List; /** * Test 2 version E. * * @author EECS2030E Fall 2016 * */ public class Test2E { /** * The maximum number of digits in a Java int. */ public static final int MAX_DIGITS = 10; private Test2E() { // empty by design } /** * Computes the average value of three numbers. * * @param a * a number * @param b * a number * @param c * a number * @return the average of a, b, and c */ public static double avg(int a, int b, int c) { return (0.0 + a + b + c) / 3.0; } /** * Given a list containing exactly 2 integers, swaps the positions of the * integers in the list. For example, given a list * *
* [-5, 9]
*
*
* swap2
modifies the list so that it becomes
*
*
*
* If joining the digits of the list produces a positive value greater
* than
* If joining the digits of the list produces a negative value less
* than [9, -5]
*
* @pre t is not null
*
* @param t
* a list containing exactly 2 integers
* @throws IllegalArgumentException
* if the list does not contain exactly 2 integers
*/
public static void swap2(Listt
greater than max
. An empty list is returned
* if no value in t
is greater than max
.
* The list t
is not changed by this method.
* For example, if max == 5
then:
*
*
* t Test2E.allGreaterThan(t, max)
* --------------------------------------------------
* [] []
* [4] []
* [9] [9]
* [4, 5, 6, 7, 8] [6, 7, 8]
*
*
* @pre t is not null
* @param t
* a list of values
* @param max
* all values in the returned list will be greater than
* max
* @return a new list containing all of the values in t
that
* are greater than max
*/
public static Listt
whose elements are single digits, returns
* the int value formed by joining the digits.
* The list t
is not changed by this method.
* For example, here are
* some lists and their corresponding int values:
*
*
* [] (the empty list) 0
* [4] 4
* [5, 2] 52
* [8, 7, 3] 873
* [-1, 0, 0, 0] -1000
*
*
* Integer.MAX_VALUE
then Integer.MAX_VALUE
* is returned.
*
* Integer.MIN_VALUE
then Integer.MIN_VALUE
* is returned.
*
* @pre1 t is not null
*
* @pre2 the elements of t are integers consisting of
* exactly one digit
*
* @pre3 the first element of t may be negative or
* positive, but not zero
*
* @pre4 all elements except the first are positive or zero
*
* @param t
* a list of digits
* @return the int value corresponding to the digits in t
*/
public static int toInt(List