public class Lab0 extends Object
Modifier and Type | Field and Description |
---|---|
static String |
COURSE_NAME
The course name for EECS2030.
|
Modifier and Type | Method and Description |
---|---|
static String |
alternatingCaps(String s)
Returns the string formed by alternating the case of the characters in
the specified string.
|
static double |
avg(int a,
int b)
Compute the average of two values as a
double value. |
static int |
compareTo(Range r1,
Range r2)
Compares two
Range instances by their widths. |
static int |
contains(double x,
Range range)
Determine if a value
x is strictly inside the given
Range . |
static int |
flipBit(int x)
Returns the result of flipping the specified bit.
|
static String |
getCourseName()
Returns the course name as the string.
|
static boolean |
isInsideUnitSquare(double x,
double y)
Determine if the point
(x, y) is inside the unit square. |
static boolean |
isOdd(int x)
Determine if an integer
x is odd. |
static boolean |
isOnUnitCircle(double x,
double y)
Determine if the point
(x, y) is exactly on the perimeter of
a circle with center (0, 0) and having radius equal to
1 . |
static boolean |
isOutsideUnitSquare(double x,
double y)
Determine if the point
(x, y) is outside the unit square. |
static int |
lastTwoDigits(int n)
Returns the last two digits of a positive integer base-10 number.
|
static int |
maxInt()
Returns the maximum (most positive) value that an
int can
represent. |
static char |
middleChar(String s)
Returns the character located in the middle of the string.
|
static double |
minDouble()
Returns the minimum positive value greater than zero that a
double can represent. |
static int |
removeLastTwoDigits(int n)
Removes the last two digits of a positive integer base-10 number.
|
static String |
toString(Range r)
Returns a string representation of a
Range that is different
than the one returned by Range.toString . |
static double |
windChill(double airTemp,
double windSpeed)
Returns the wind chill for air temperatures equal to or below 0 degrees
Celcius and wind velocities equal to or greater than 5 km/h.
|
public static final String COURSE_NAME
public static int maxInt()
int
can
represent.public static double minDouble()
double
can represent.public static int removeLastTwoDigits(int n)
n
is less than 100
then the value of
0
is returned.n
- a positive integerpublic static int lastTwoDigits(int n)
0
then only the last digit is
returned. If n
is less than 100
then the value
of n
is returned.n
- a positive integerpublic static double avg(int a, int b)
double
value.a
- a valueb
- a second valuepublic static double windChill(double airTemp, double windSpeed)
Wind chill is an index that indicates how cold the weather feels to the average person when there is some wind. For example, if the air temperature is -5 degrees Celcius and the wind chill is -15 then it means that it feels similar to a windless day where the temperature is -15 degrees Celcius.
airTemp
- the temperature in degrees Celcius (must be 0 degrees or less)windSpeed
- the wind speed in km/h (must be 5 km/h or greater)public static boolean isOdd(int x)
x
is odd.x
- a valuepublic static boolean isOnUnitCircle(double x, double y)
(x, y)
is exactly on the perimeter of
a circle with center (0, 0)
and having radius equal to
1
.x
- the x-coordinate of the pointy
- the y-coordinate of the pointpublic static boolean isInsideUnitSquare(double x, double y)
(x, y)
is inside the unit square. The
unit square is the square whose sides have length 1, whose bottom left
corner has coordinates (0, 0), and whose top right corner has coordinates
(1, 1). A point on the perimeter of the unit square is considered to be
inside the square.x
- the x-coordinate of the pointy
- the y-coordinate of the pointpublic static boolean isOutsideUnitSquare(double x, double y)
(x, y)
is outside the unit square.
The unit square is the square whose sides have length 1, whose bottom
left corner has coordinates (0, 0), and whose top right corner has
coordinates (1, 1). A point on the perimeter of the unit square is
considered to be inside the square.x
- the x-coordinate of the pointy
- the y-coordinate of the pointpublic static int flipBit(int x)
A bit is the digit used in the binary number system. A bit can have a value of zero or one (with no other value allowed). Flipping a bit changes the value of the bit to the other value; flipping a bit that is zero changes it to one, and flipping a bit that is one changes it to zero.
x
- a bitBadBitException
- if x is not a bit (has a value that is not zero and not one).public static int contains(double x, Range range)
x
is strictly inside the given
Range
. A value exactly at the minimum or maximum of the
range is considered outside of the range.x
- a valuerange
- a Range to checkpublic static int compareTo(Range r1, Range r2)
Range
instances by their widths.r1
- a Ranger2
- a second Rangepublic static String getCourseName()
public static String toString(Range r)
Range
that is different
than the one returned by Range.toString
.
The returned string has the form "range from x to y"
where x
is the minimum value of the range and y is the maximum value of the
range.
r
- a Range instancepublic static char middleChar(String s)
s
has an even number of characters then the middle character
is taken to be the first character in the second half of the string
(i.e., the middle character of the string "abcd"
is
'c'
.s
- a string of length 1 or greaterIllegalArgumentException
- if s is emptypublic static String alternatingCaps(String s)
alternatingCaps("a")
returns "a"
alternatingCaps("ab")
returns "aB"
alternatingCaps("abc")
returns "aBc"
alternatingCaps("XYZ")
returns "xYz"
alternatingCaps("Toronto")
returns "tOrOnTo"
alternatingCaps("eecs2030")
returns "eEcS2030"
The conversion of characters to lower or uppercase is identical to
that performed by the methods Character.toLowerCase(int)
and Character.toLowerCase(int)
s
- a string