public class Lab1
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
COURSE_NAME
The course name for EECS2030.
|
static int |
DEGREES_IN_CIRCLE
The number of degrees in a circle.
|
static int |
QUARTER_VALUE
The number of cents equal to a Canadian quarter coin.
|
| Modifier and Type | Method and Description |
|---|---|
static double |
avg(int a,
int b)
Compute the average of two values.
|
static char |
charFromEnd(java.lang.String s,
int n)
Returns the character n positions from the end of the string s.
|
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 |
frequency(java.util.List<java.lang.String> t,
java.lang.String target)
Returns the number of strings in the list t that are equal to the target
string.
|
static java.lang.String |
getCourseName()
Returns the course name as the string.
|
static boolean |
isEven(int x)
Determine if an integer
x is even. |
static boolean |
isGradeA(double percent)
Returns true if the given grade in percent is equal to a letter grade of A,
and false otherwise.
|
static boolean |
isGradeOutOfRange(double percent)
Returns true if the given grade in percent is outside the range of normal
grades (less than 0 or greater than 100), and false otherwise.
|
static boolean |
isInsideUnitCircle(double x,
double y)
Determine if the point
(x, y) is inside the perimeter of a
circle with center (0, 0) and having radius equal to
1. |
static boolean |
isLeapYear(int year)
Returns true if year is a leap year and false otherwise.
|
static boolean |
isPythagTriple(int a,
int b,
int c)
Given three integers: a, b, and c; return true only if they can form a Pythagorean triple.
|
static int |
maxInt()
Returns the maximum (most positive) value that an
int can
represent. |
static double |
minDouble()
Returns the minimum positive value greater than zero that a
double can represent. |
static double |
normal(double x)
Computes the standard normal distribution probability density function (see
the lab document for the actual formula).
|
static int |
numQuarters(int cents)
Returns the largest number of Canadian quarters (each worth 25 cents) whose
total value does not exceed the given number of cents.
|
static void |
repair(java.util.List<java.lang.Integer> t)
Sorts the elements of the list t so that the elements are in ascending order.
|
static void |
sort2(java.util.List<java.lang.Integer> t)
Sorts a list of two integers so that the elements are in descending order
(largest to smallest).
|
static java.lang.String |
toString(Range r)
Returns a string representation of a
Range that is different
than the one returned by Range.toString. |
static int |
wrapAngle(int degrees)
Wraps an angle given in degrees so that it lies in the range of -359 degrees
to 359 degrees.
|
public static final java.lang.String COURSE_NAME
public static final int QUARTER_VALUE
public static final int DEGREES_IN_CIRCLE
public static int maxInt()
int can
represent.public static double minDouble()
double can represent.public static int numQuarters(int cents)
cents - a positive number of centspublic static int wrapAngle(int degrees)
degrees wrapAngle(degrees) returns 0 0 1 1 -1 -1 359 359 -359 -359 360 0 (wraps around to 0 degree) -360 0 (wraps around to 0 degree) 361 1 (wraps around to 1 degree) -361 -1 (wraps around to -1 degree) 725 5 (wraps around to 5 degrees) -730 -10 (wraps around to -10 degrees) 3652 52 (wraps around to 52 degrees)
degrees - an angle in degreespublic static double avg(int a,
int b)
a - a valueb - a second valuepublic static double normal(double x)
x - a valuepublic static boolean isEven(int x)
x is even.x - a valuepublic static boolean isInsideUnitCircle(double x,
double y)
(x, y) is inside 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 isGradeA(double percent)
percent - a grade in percentpublic static boolean isGradeOutOfRange(double percent)
percent - a grade in percentpublic static boolean isLeapYear(int year)
A year is always a leap year if it is evenly divisible by 400; for all other years, a year is a leap year if it is evenly divisible by 4 and not evenly divisible by 100. For example:
isLeapYear(2000) returns true (2000 is divisible by 400) isLeapYear(1900) returns false (1900 is divisible by 4 and 100) isLeapYear(2004) returns true (2004 is divisible by 4 but not 100) isLeapYear(2005) returns false (2005 is not divisible by 4)
year - a yearjava.lang.IllegalArgumentException - if year is less than 1582 (the year the Gregorian
calendar was adopted)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 java.lang.String getCourseName()
public static java.lang.String toString(Range r)
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.
r - a Range instancepublic static char charFromEnd(java.lang.String s,
int n)
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
s - a string of length 1 or greatern - the desired location of the character counting from the end of the
stringjava.lang.IllegalArgumentException - if the character located n positions from the end of the string
does not existpublic static void sort2(java.util.List<java.lang.Integer> t)
t - a listjava.lang.IllegalArgumentException - if the size of list is not equal to 2public static int frequency(java.util.List<java.lang.String> t,
java.lang.String target)
t - the list to searchtarget - the string to search forpublic static void repair(java.util.List<java.lang.Integer> t)
[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.
t - a list of almost sorted elementspublic static boolean isPythagTriple(int a,
int b,
int c)
isPythagTriple(4,3,5) output: true isPythagTriple(5,3,4) output: true isPythagTriple(6,3,5) output: false isPythagTriple(1,1,2) output: false
a - an integer number in the tripleb - an integer number in the triplec - an integer number in the triplejava.lang.IllegalArgumentException - if a, b, or c is zero