Guest User

Untitled

a guest
Nov 13th, 2014
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. package com.FisheyLP.IntToString;
  2.  
  3. public class Umrechner {
  4.  
  5. public static String[] einser = new String[] { "null", "ein", "zwei",
  6. "drei", "vier", "fünf", "sechs", "sieben", "acht", "neun" };
  7. public static String[] zehner = new String[] { null, "zehn", "zwanzig",
  8. "dreissig", "vierzig", "fünfzig", "sechzig", "siebzig", "achtzig",
  9. "neunzig" };
  10.  
  11. public String convertToString(int i) {
  12. String text = "";
  13.  
  14. boolean isMinus = i < 0;
  15.  
  16. if (isMinus) {
  17. i = Math.abs(i);
  18. }
  19.  
  20. if (containsHunderter(i)) {
  21. text = einser[getHunderter(i)] + "hundert";
  22. if (containsZehner(i)) {
  23. text = einser[getHunderter(i)] + "hundert"
  24. + zehner[getZehner(i)];
  25.  
  26. String zusatz = null;
  27. if (getEinser(i) == 1)
  28. zusatz = "elf";
  29. if (getEinser(i) == 2)
  30. zusatz = "zwölf";
  31. if (containsEinser(i)) {
  32. if (getZehner(i) < 2) {
  33.  
  34. if (zusatz == null) {
  35. text = einser[getHunderter(i)] + "hundert"
  36. + einser[getEinser(i)]
  37. + zehner[getZehner(i)];
  38. } else {
  39. text = einser[getHunderter(i)] + "hundert" + zusatz;
  40. }
  41. } else {
  42. text = einser[getHunderter(i)] + "hundert"
  43. + einser[getEinser(i)] + "und"
  44. + zehner[getZehner(i)];
  45. }
  46. }
  47. } else {
  48. text = einser[getHunderter(i)] + "hundert"
  49. + einser[getEinser(i)];
  50. }
  51.  
  52. text = text.replace("eins", "ein");
  53. } else if (containsZehner(i)) {
  54. text = zehner[getZehner(i)];
  55. if (containsEinser(i)) {
  56. if (i == 11)
  57. return "Elf";
  58. if (i == 12)
  59. return "Zwölf";
  60.  
  61. if (getZehner(i) < 2) {
  62. text = einser[getEinser(i)] + zehner[getZehner(i)];
  63. } else {
  64. text = einser[getEinser(i)] + "und" + zehner[getZehner(i)];
  65. }
  66. }
  67. } else {
  68. text = einser[getEinser(i)];
  69. }
  70.  
  71. if (text.endsWith("ein")) {
  72. text = text + "s";
  73. }
  74. text = text.replace("achtzig", "achzig");
  75.  
  76. text = text.substring(0, 1).toUpperCase() + text.substring(1);
  77.  
  78. if (isMinus) {
  79. text = "Minus " + text;
  80. }
  81. return text;
  82. }
  83.  
  84. public static int getEinser(int i) {
  85. String str = Integer.toString(i);
  86. String value = str.split("")[str.length()];
  87.  
  88. return Integer.parseInt(value);
  89. }
  90.  
  91. public static int getZehner(int i) {
  92. String str = Integer.toString(i);
  93. String value = str.split("")[str.length() - 1];
  94.  
  95. return Integer.parseInt(value);
  96. }
  97.  
  98. public static int getHunderter(int i) {
  99. String str = Integer.toString(i);
  100. String value = str.split("")[str.length() - 2];
  101.  
  102. return Integer.parseInt(value);
  103. }
  104.  
  105. public static boolean containsEinser(int i) {
  106. String text = Integer.toString(i);
  107.  
  108. return !text.endsWith("0");
  109. }
  110.  
  111. public static boolean containsZehner(int i) {
  112. String text = Integer.toString(i);
  113.  
  114. if (text.length() < 2)
  115. return false;
  116.  
  117. return !text.split("")[text.length() - 1].contains("0");
  118. }
  119.  
  120. public static boolean containsHunderter(int i) {
  121. String text = Integer.toString(i);
  122.  
  123. if (text.length() < 3)
  124. return false;
  125.  
  126. return !text.split("")[text.length() - 2].contains("0");
  127. }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment