COW 10 Computation Of the Week (10) Task #1 – Do the exercises

advertisement
COW 10
Computation Of the Week (10)
Task #1 – Do the exercises in Lesson 40, 42, and 43 in Blue Pelican
Task 2 – Recursion Practice – Create a program that produces the following output to the screen.
Each item sent to standard output should be a value stored in a variable. Each line should be produced
by a separate recursive function:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,
2, 4, 6, 8, 10, 12, 14, 16, 18, 20,
1, 2, 4, 8, 16, 32, 64, 128, 256, 512,
1, 3, 7, 15, 31, 63, 127, 255, 511,
1, 4, 10, 22, 46, 94, 190, 382, 766,
1, 2, 5, 14, 41, 122, 365, 1094,
1, -10, 100, -1000, 10000, -100000,
1, -1, 1, -1, 1, -1, 1, -1, 1, -1,
2, 4, 16, 256, 65536,
Task 3 – Coding Bat Recursion Practice – Obtain at least 5 stars in Recursion–1on CodingBat.com
Task 4 – MyMath Class
So far you might have used the Math class for a number of your labs. Now you will create your own
class which does the same thing called MyMath. You are NOT to use the Math class in any way for
this. You will need to include all the following in your MyMath class:
1. Constants – create two constants called E that should store the base of the natural logarithms
and PI that will store pi. You should have at least ten significant digits.
2. Methods – your class should have the following methods:
a. Hint – for random you should try using the system clock
b. Hint – sqrt is the hardest one to program, leave that one until the end
static double abs(double a)
Returns the absolute value of a double value.
static int abs(int a)
Returns the absolute value of an int value.
static long abs(long a)
Returns the absolute value of a long value.
static double ceil(double a)
Returns the smallest (closest to negative infinity) double value that is greater than
or equal to the argument and is equal to a mathematical integer.
static double exp(double a)
Returns Euler's number e raised to the power of a double value.
static double expm1(double x)
Returns ex -1.
static double floor(double a)
Returns the largest (closest to positive infinity) double value that is less than or
equal to the argument and is equal to a mathematical integer.
static double max(double a, double b)
Returns the greater of two double values.
static int max(int a, int b)
Returns the greater of two int values.
static double min(double a, double b)
Returns the smaller of two double values.
static int min(int a, int b)
Returns the smaller of two int values.
static double pow(double a, double b)
Returns the value of the first argument raised to the power of the second argument.
static double random()
Returns a double value with a positive sign, greater than or equal to 0.0 and less
than 1.0.
static long round(double a)
Returns the closest long to the argument.
static double signum(double d)
Returns the signum function of the argument; zero if the argument is zero, 1.0 if
the argument is greater than zero, -1.0 if the argument is less than zero.
static double sqrt(double a)
Returns the correctly rounded positive square root of a double value.
static double toDegrees(double angrad)
Converts an angle measured in radians to an approximately equivalent angle
measured in degrees.
static double toRadians(double angdeg)
Converts an angle measured in degrees to an approximately equivalent angle
measured in radians.
Task 5 – Write a program that will ask the user for the number of students in the class. The program
should then create an array list of strings, prompt the user for all the names, and store each name in the
array list. You should then create the following static methods:





printList(ArrayList<String> names) – prints each name on the list in numbered order
printListInReverse(ArrayList<String> names) – prints each name on the list in reverse order
findLongestName(ArrayList<String> names) – finds the longest name in the list and returns it
findShortestName(ArrayList<String> names) – finds the shortest name in the list and returns it
elliminate(ArrayList<String> names, String badName) – eliminates any occurrence of
badName and eliminates it from the list
Once you have your methods programmed, you should test them in your main program.
Task 6 – Decide on a grouping or real world object and create a class hierarchy for those objects.
Download