Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. /**
  2. * This Class converts capitals to lower case and
  3. * small letters to capitals, without changing of
  4. * special characters.
  5. * @author Droxl
  6. */
  7. public class LetterConverter {
  8. /**
  9. * This method changes the character to lower case.
  10. * @param c The character which is given.
  11. * @return Returns the lower case character.
  12. */
  13. public static char getLowerCase(char c) {
  14. c = Character.toLowerCase(c);
  15. return c;
  16. }
  17. /**
  18. * This method changes the character to upper case.
  19. * @param c The character which is given.
  20. * @return Returns the upperer case character.
  21. */
  22. public static char getUpperCase(char c) {
  23. c = Character.toUpperCase(c);
  24. return c;
  25. }
  26. /**
  27. * This method converts capitals to upper or lower case.
  28. * It depends on which type character is given.
  29. * @param c The given character.
  30. * @return Returns the opposite of the
  31. * type of character which is entered.
  32. */
  33. public static char convertLetter(char c) {
  34. /*This character serves as return-value.*/
  35. char returnValue;
  36. /*Here the converting begins...*/
  37. if ((c == 'a') || (c == 'b') || (c == 'c')
  38. || (c == 'd') || (c == 'e') || (c == 'f')
  39. || (c == 'g') || (c == 'h') || (c == 'i')
  40. || (c == 'j') || (c == 'k') || (c == 'l')
  41. || (c == 'm') || (c == 'n') || (c == 'o')
  42. || (c == 'p') || (c == 'q') || (c == 'r')
  43. || (c == 's') || (c == 't') || (c == 'u')
  44. || (c == 'v') || (c == 'w') || (c == 'x')
  45. || (c == 'y') || (c == 'z')) {
  46. /*...to capitals.*/
  47. returnValue = getUpperCase(c);
  48. } else {
  49. /*In the other case to small letters.*/
  50. returnValue = getLowerCase(c);
  51. }
  52. /*Returns capital or lower case letters depending on what is entered.*/
  53. return returnValue;
  54. }
  55. /**
  56. * Main-method() which executes the given methods above.
  57. * @param args is not used.
  58. */
  59. public static void main(String[] args) {
  60. /*Converts to --> A.*/
  61. System.out.println(convertLetter('a'));
  62. /*Converts to --> a.*/
  63. System.out.println(convertLetter('A'));
  64. /*Keeps steady @.*/
  65. System.out.println(convertLetter('@'));
  66. /*Converts to --> B.*/
  67. System.out.println(convertLetter('b'));
  68. /*Converts to --> b.*/
  69. System.out.println(convertLetter('B'));
  70. /*Keeps steady @.*/
  71. System.out.println(convertLetter('@'));
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement