ASSIGNMENT_01

advertisement
Practice Problems: Set 1 part A
1. Implement a method named triple that will accept one string parameter named alpha. It will return the
first letter tripled.
Example: if the string is jackson then the method will return jjj.
2. Implement a method named area that will accept 2 integer parameters named base and height. It will
return the area of the right triangle represented by those parameters.
3. Implement a method named temp that accepts one integer parameter named celsius. The method will
return the fahrenheit temperature that is equivalent to the celsius temperature it received.
4. Implement a method named quintSum that accepts 2 integer parameters named first and last. The
method will return the sum of the parameters quintupled.
5. Implement a method named quotes that accepts 2 String parameters named first and last. The method
will return the 2 strings concatenated enclosed in a set of double quotes.
Example: if the strings are some and time then the method will return “sometime” (quotes included).
6. Implement a method named letter that will ask the user to enter a word of 2 letters. The method will
print to the screen the letter (of the alphabet) that is midway between the first and the last letters.
If the word is ‘am’ then the output should be: g
7. Implement a method named reverse that will ask the user to enter 3 words. The method will print the
three words in reverse order.
If the words were “name that tune” the output would be: tune that name
8. Implement a method named isBig that will accept one string parameter named alpha. It will return
true only if the length of the string is greater than 6.
9. Implement a method named oddEven that takes one String parameter named message. The method
will return the middle character if the string has an odd length or the first and last characters if the
string has an even length.
Example: If message is “tubular” return u -------- If message is “boxing” return bg
Practice Problems: Set 1 part B
10. Implement a method named looks that accepts 2 integer parameters named width, length. It will return
the string “skinny” if the length is more than twice the width. If the width is more than twice the length,
it will return the string “fat”. If they are the same it will return the string “square”.
11. Implement a method named inRange that accepts one integer parameter named original. The method
will return the true only if the number is in the range of 1 – 100 inclusive.
12. Implement a method named greater that accepts 2 integer parameters named sideA and sideB. The
method will return true only if sideA is greater than sideB.
13. Implement a method named outlier that will generate a random number from 1 – 30. It will return
true if the number is less than 10 or greater than 20.
14. Implement a method named numBall that takes two integer parameters named num1 and num2. If
both integers are odd return -1. If both integers are even, return 1. Otherwise return 0.
15. Implement a method named positive. The method accepts 3 integer parameters named: alfa, beta,
gama. The method returns the number of non-negative integers it received.
16. Implement a method named bigNum that takes three integer parameters named first, mid, and last.
The method will return the largest of the three integers. (all 3 have different values)
17. Implement a method named roll. The method generates a random integer named number in the range
from
1 – 100 inclusive. The method returns one of the following strings:
a. “even > 50”
“odd >50”
“even < 50”
“odd <50”
“50”
18. Implement a method named posNeg that generates 1000 random integers. The range of the numbers
should be from -5 to +5 inclusive. The method will print to the screen the number of positive values, the
number of negative values and the number of zeros generated.
Example output:
positive: <number>
negative: <number>
zeros: <number>
19. Implement a method named alpha that will generate 50 random characters. The only valid characters
to use are the set {a, b, c} (3 different chars). The method will print to the screen the randomly
generated characters on one line (space separated) and will also return the number of times that the
middle character (b) was generated.
Practice Problems: Set 1 part C
20. Implement a method named reverse that takes one String parameter named fragment. The method
will print to the screen all of the characters of the string in reverse order. It will print no more than
20 characters on a line (assuming more than one line is needed).
21. Implement a method named rangeSum that takes two integer parameters named first and last. The
method will return the sum all of the integers in the range starting with first and ending with last. Both
the last and the first are included in the sum.
22. Implement a method named binary. The method will print (decimal format) to the screen the first 15
non-negative powers of 2.
23. Implement a method named digits that takes one integer parameter named num. The method will
return the number of digits in the integer.
You CANNOT use any methods of the String or Integer Wrapper Classes (to be discussed later).
Example: (if the integer is 342712) the method will return: 6 // (number of digits)
24. Implement a method named vowels that takes one String parameter named ‘message’. The method
will print to the screen the total number of lower case ‘e’ found and the total number of lower case ‘a’
found in the string.
25. Implement a method named multiple that takes two integer parameters named num1 and num2
If one integer is an exact multiple of the other integer return true.
Example
If the numbers are 69 and 23, then 69 is an exact multiple of 23 (3X)
26. Implement a method named numbers that takes two integer parameter named start and range.
The method will generate 40 integers using start and range as parameters to the random number
generator. The value of range will be greater than 1000. The method will print to the screen both
the highest value and lowest value generated
27. Implement a method named ascends that takes three integer parameters named one, two, and three.
The method will print to the screen the numbers in ascending order.
(The numbers are not necessarily all different.)
Download