package eecs2030.test2;
import java.util.ArrayList;
import java.util.List;
/**
* Test 2 version F.
*
* @author EECS2030E Fall 2016
*
*/
public class Test2F {
/**
* The size of the list required by the method Test2F.min2
*/
public static final int MIN2_LIST_SIZE = 2;
private Test2F() {
// empty by design
}
/**
* Returns true if value
is strictly greater than
* min
and strictly less than max
, and false
* otherwise.
*
* @param min
* a minimum value
* @param max
* a maximum value
* @param value
* a value to check
* @return true if value
is strictly greater than
* min
and strictly less than max
, and
* false otherwise
* @pre min is greater than or equal to max
*/
public static boolean isBetween(int min, int max, int value) {
return value > min && value < max;
}
/**
* Given a list containing exactly 2 integers, returns the smaller of the
* two integers. The list t
is not modified by this method.
* For example:
*
*
* t Test2F.min2(t) * --------------------------- * [-5, 9] -5 * [3, 3] 3 * [12, 6] 6 ** * @pre t is not null * * @param t * a list containing exactly 2 integers * @return * the minimum of the two values in t * @throws IllegalArgumentException * if the list does not contain exactly 2 integers */ public static int min2(List
t
that are greater than
* value
. The list t
is not modified by this method.
* For example, if value == 3
then:
*
* * t Test2F.countGreaterThan(t, 3) * ---------------------------------------------------- * [] 0 * [-5] 0 * [3, 4] 1 * [12, 6, 8, 2, 2, 2] 3 ** * @param t * a list * @param value * a value * @return number of elements in t that are greater than value * @pre t is not null */ public static int countGreaterThan(List
n
digits from the the end of aNumber
. The
* method will never remove all of the digits of aNumber
. If
* n
is greater than the number of digits in
* aNumber
then the first digit of aNumber
is
* returned. For example:
*
* * aNumber n Test2F.removeDigits(aNumber, n) * ------------------------------------------------ * 1 0 1 * 2 1 2 * 87 1 8 * 100353 3 100 * -9325256 5 -93 * -9325256 999 -9 ** * @param aNumber * a number * @param n * the number of digits to remove from the end of aNumber * @return the number equal to removing n digits from the end of aNumber, or * the first digit of aNumber if n is greater than or equal to the * number of digits in aNumber */ public static int removeDigits(int aNumber, int n) { for (int i = 0; i < n; i++) { int remaining = aNumber / 10; if (remaining == 0) { return aNumber; } else { aNumber /= 10; } } return aNumber; } public static void main(String[] args) { // isBetween int min = 1; int max = 10; int value = 5; System.out.println( String.format("isBetween(%d, %d, %d) : ", min, max, value) + Test2F.isBetween(min, max, value)); // min2 List