Java Reference
In-Depth Information
For an added challenge, make your method throw an IllegalArgumentException if the user passes a grade lower
than 0 or higher than 100 .
13. Write a method called printPalindrome that accepts a Scanner for the console as a parameter, and prompts the
user to enter one or more words and prints whether the entered String is a palindrome (i.e., reads the same
forwards as it does backwards, like "abba" or "racecar") .
For an added challenge, make the code case-insensitive, so that words like “Abba” and “Madam” will be
considered palindromes.
14. Write a method called swapPairs that accepts a String as a parameter and returns that String with each pair of
adjacent letters reversed. If the String has an odd number of letters, the last letter is unchanged. For example, the
call swapPairs("example") should return "xemalpe" and the call swapPairs("hello there") should return
"ehll ohtree" .
15. Write a method called wordCount that accepts a String as its parameter and returns the number of words in
the String . A word is a sequence of one or more nonspace characters (any character other than '' ). For example,
the call wordCount("hello") should return 1 , the call wordCount("how are you?") should return 3 , the call
wordCount(" this string has wide spaces ") should return 5 , and the call wordCount(" ") should
return 0 .
16. Write a method called quadrant that accepts as parameters a pair of double values representing an ( x , y ) point and
returns the quadrant number for that point. Recall that quadrants are numbered as integers from 1 to 4 with the
upper-right quadrant numbered 1 and the subsequent quadrants numbered in a counterclockwise fashion:
y-axis
Quadrant 2
Quadrant 1
x-axis
Quadrant 3
Quadrant 4
Notice that the quadrant is determined by whether the x and y coordinates are positive or negative numbers. Return 0 if
the point lies on the x- or y -axis. For example, the call of quadrant(-2.3, 3.5) should return 2 and the call of
quadrant(4.5, -4.5) should return 4 .
Programming Projects
1. Write a program that prompts for a number and displays it in Roman numerals.
2. Write a program that prompts for a date (month, day, year) and reports the day of the week for that date. It might be
helpful to know that January 1, 1601 was a Monday.
3. Write a program that compares two college applicants. The program should prompt for each student's GPA, SAT,
and ACT exam scores and report which candidate is more qualified on the basis of these scores.
 
Search WWH ::




Custom Search