Advertisement
Chame

Untitled

Nov 26th, 2011
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. package edu.hdsb.rbhs.ics3u.closs.u3;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class NumberOfWords2 {
  6.  
  7. public static String tens = null;
  8. public static String ones = null;
  9. public static String word = null;
  10. public static String teens = null;
  11.  
  12. public static String WordInput() {
  13. System.out.print("Please input the number (in digits): ");
  14. Scanner input = new Scanner(System.in);
  15. word = input.nextLine();
  16. return word;
  17. }
  18.  
  19. public static void WelcomeStatement() {
  20. System.out.println("This program that converts any number from 10 to 99 from its digit representation to its word representation. For example: 45 would give FORTY FIVE.\n");
  21. }
  22.  
  23. public static String onesPosition() {
  24. if (word.charAt(1) == 1) {
  25. ones = "ONE ";
  26. } else if (word.charAt(1) == 2) {
  27. ones = "TWO ";
  28. } else if (word.charAt(1) == 3) {
  29. ones = "THREE ";
  30. } else if (word.charAt(1) == 4) {
  31. ones = "FOUR ";
  32. } else if (word.charAt(1) == 5) {
  33. ones = "FIVE ";
  34. } else if (word.charAt(1) == 6) {
  35. ones = "SIX ";
  36. } else if (word.charAt(1) == 7) {
  37. ones = "SEVEN ";
  38. } else if (word.charAt(1) == 8) {
  39. ones = "EIGHT ";
  40. } else if (word.charAt(1) == 9) {
  41. ones = "NINE ";
  42. }
  43. return ones;
  44. }
  45.  
  46. public static String teensPosition() {
  47.  
  48. if (word.charAt(0) == 1) {
  49. if (word.charAt(1) == 1) {
  50. teens = "ELEVEN";
  51. tens = " ";
  52. ones = " ";
  53. } else if (word.charAt(1) == 2) {
  54. teens = "TWELVE";
  55. tens = " ";
  56. ones = " ";
  57. } else if (word.charAt(1) == 3) {
  58. teens = "THIRTEEN";
  59. tens = " ";
  60. ones = " ";
  61. } else if (word.charAt(1) == 4) {
  62. teens = "FOURTEEN";
  63. tens = " ";
  64. ones = " ";
  65. } else if (word.charAt(1) == 5) {
  66. teens = "FIFTEEN";
  67. tens = " ";
  68. ones = " ";
  69. } else if (word.charAt(1) == 6) {
  70. teens = "SIXTEEN";
  71. tens = " ";
  72. ones = " ";
  73. } else if (word.charAt(1) == 7) {
  74. teens = "SEVENTEEN";
  75. tens = " ";
  76. ones = " ";
  77. } else if (word.charAt(1) == 8) {
  78. teens = "EIGHTEEN";
  79. tens = " ";
  80. ones = " ";
  81. } else if (word.charAt(1) == 9) {
  82. teens = "NINETEEN";
  83. tens = " ";
  84. ones = " ";
  85. }
  86. }
  87. return teens;
  88. }
  89.  
  90. public static String tensPosition() {
  91.  
  92.  
  93. if (word.charAt(0) == 2) {
  94. tens = "TWENTY ";
  95. } else if (word.charAt(0) == 3) {
  96. tens = "THIRTY ";
  97. } else if (word.charAt(0) == 4) {
  98. tens = "FORTY ";
  99. } else if (word.charAt(0) == 5) {
  100. tens = "FIFTY ";
  101. } else if (word.charAt(0) == 6) {
  102. tens = "SIXTY ";
  103. } else if (word.charAt(0) == 7) {
  104. tens = "SEVENTY ";
  105. } else if (word.charAt(0) == 8) {
  106. tens = "EIGHTY ";
  107. } else if (word.charAt(0) == 9) {
  108. tens = "NINETY ";
  109. }
  110. return tens;
  111. }
  112.  
  113. public static void main(String[] args) {
  114. WelcomeStatement();
  115. WordInput();
  116. onesPosition();
  117. tensPosition();
  118. teensPosition();
  119.  
  120. System.out.print(teens + tens + ones );
  121. }
  122. }
  123.  
  124.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement