The first rule of modern programming is "don't write new code; find reusable code on the Internet, even if it's in another language!".
The second rule is "if you write code, try to maximize its usefulness.". Designing and implementing methods provides practice in that skill.
Implement and test the method double toMeters(double in, String units). The units argument can be "inch", "foot", "yard", or "mile".
Implement and test the method String format(String tenDigits) to convert a phone number 9876543210 to (987) 654-3210.
The maximum height of a projectile shot on a level surface with an initial velocity v at angle a in a world with gravity g is v*v*(sin a)*(sin a)/(2g). Be sure that v and g use the same units. Earth gravity is (9.80665 m/s)/s. Check your calculations using an online app.
double height(double velocity, double angle, double gravity)
Implement and test a method to reverse a String. String reverse(String in) For example, "hello world" reversed is "dlrow olleh".
Implement a predicate to test if a double value is an integer. boolean isInt(double d) Test the predicate in a program that processes command line arguments. The arguments are a mixture of numbers (ints and doubles). Run the program three times with a) b) c) as command-line arguments. Print each number on a separate line and whether it is an int or a double. Test your program with each of the following lists of arguments:
a) 1 2 3 -4 5 0 b) 1.1 2.2 3.3 44444.4 c) 1 2.9 3 4.9 555 6.9
6. For faster sorting of letters, the U.S. Postal Service encourages companies that send large volumes of mail to use a bar code denoting the ZIP code. The encoding scheme for a five-digit ZIP code is shown below. There are full-height frame bars on each side.
The five encoded digits are followed by a check digit, which is computed as follows:
Add up all digits, and choose the check digit to make the sum a multiple of 10. For example, the sum of the digits in the ZIP code 95014 is 19, so the check digit is 1 to make the sum equal to 20.
Each digit of the ZIP code, and the check digit, is encoded according to the table at right, where 0 denotes a half bar and 1 a full bar. Note that they represent all combinations of two full and three half bars. The digit can be computed easily from the bar code using the column weights 7,4,2,1,0.
For example, 01100 is 0 x 7 + 1 x 4 + 1 x 2 + 0 x 1 + 0 x 0 =6
74210 weight
1 00011
2 00101
3 00110
4 01001
5 01010
6 01100
7 10001
8 10010
9 10100
0 11000
The only exception is 0, which would yield 11 according to the weight formula.
Write a program that asks the user for a ZIP code and prints the bar code.
Use : for half bars, I for full bars. For example, 95014 with check digit 1 becomes.
||:|:: :|:|: ||::: :::|| :|::| :::|||
7. The fibonacci series is a series in which each number is the sum of the previous two numbers. The number at a particular position in the fibonacci series can be obtained using a recursive function. int fibonacci(int n). The basis cases are f(0)=0 and f(1)=1. Implement and test the function.
8. Complete the Recursion exercises (up to and including Recursive Powers) at Khan Academy. Code in Java at JDoodle. www.khanacademy.org/computing/computer-science/algorithms/recursive-algorithms/a/recursion