Advertisement
Guest User

iinJAVA

a guest
Apr 18th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.81 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3. class Scratch {
  4. static void wrong(int cheakCentury, int cheakDay, int cheakMonth, int cheakLetter, int cheakLength)
  5. {
  6. System.out.println(cheakCentury+" "+cheakDay+" "+cheakMonth+" "+cheakLetter);
  7. if(cheakLength == 1)
  8. {
  9. System.out.println("invalid IIN");
  10. }
  11. if(cheakMonth == 1)
  12. {
  13. System.out.println("wrong month");
  14. }
  15. if(cheakDay == 1)
  16. {
  17. System.out.println("wrong day");
  18. }
  19. if(cheakCentury == 1)
  20. {
  21. System.out.println("wrong Century");
  22. }
  23. if(cheakLetter == 1)
  24. {
  25. System.out.println("error: you enter letter");
  26. }
  27. if(cheakDay ==1 && cheakMonth == 1)
  28. {
  29. System.out.println("invalid IIN");
  30. }
  31. if(cheakCentury==1 || cheakDay==1 || cheakLetter==1 || cheakMonth==1 || cheakLength==1)
  32. {
  33. System.exit(0);
  34. }
  35. }
  36.  
  37. public static void main(String[] args) {
  38. boolean wrongLength = false;
  39. Scanner in = new Scanner(System.in);
  40. String IIN = in.nextLine();
  41. System.out.println(IIN);
  42. if(IIN.length() != 12)
  43. {
  44. wrongLength = true;
  45. System.out.println("invalid IIN");
  46. System.exit(0);
  47. }
  48. boolean wrongLetter = false;
  49. for (int i = 0; i < IIN.length(); i++)
  50. {
  51. if (IIN.charAt(i) < '0' || IIN.charAt(i) > '9') {
  52. wrongLetter = true;
  53. System.out.println("invalid IIN: entered letter");
  54. System.exit(0);
  55. }
  56. }
  57. int cheakLength = wrongLength ? 1:0;
  58. String year = IIN.substring(0, 2);
  59. String month = IIN.substring(2, 4);
  60. String day = IIN.substring(4, 6);
  61. String century = IIN.substring(6, 7);
  62. int Year = Integer.parseInt(year);
  63. int Month = Integer.parseInt(month);
  64. int Day = Integer.parseInt(day);
  65. int Century = Integer.parseInt(century);
  66. boolean wrongMonth = false;
  67. boolean wrongDay = false;
  68. boolean wrongCentury = false;
  69. if (Month > 12 || Month <= 0)
  70. {
  71. wrongMonth = true;
  72. }
  73. if (Century > 6 || Century <= 0)
  74. {
  75. wrongCentury = true;
  76. }
  77. int leapYear = Year % 4;
  78. String monthout = "";
  79. switch (Month) {
  80. case 1: {
  81. monthout = "january";
  82. break;
  83. }
  84. case 2: {
  85. if (leapYear == 0)
  86. {
  87. if (Day > 29)
  88. {
  89. wrongDay = true;
  90. }
  91. else
  92. {
  93. monthout = "febuary";
  94. break;
  95. }
  96. }
  97. else
  98. {
  99. if (Day > 28)
  100. {
  101. wrongDay = true;
  102. } else
  103. {
  104. monthout = "febuary";
  105. break;
  106. }
  107. }
  108. }
  109. case 3: {
  110. monthout = "march";
  111. break;
  112. }
  113. case 4: {
  114. monthout = "april";
  115. break;
  116. }
  117. case 5: {
  118. monthout = "may";
  119. break;
  120. }
  121. case 6: {
  122. monthout = "june";
  123. break;
  124. }
  125. case 7: {
  126. monthout = "jule";
  127. break;
  128. }
  129. case 8: {
  130. monthout = "august";
  131. break;
  132. }
  133. case 9: {
  134. monthout = "september";
  135. break;
  136. }
  137. case 10: {
  138. monthout = "october";
  139. break;
  140. }
  141. case 11: {
  142. monthout = "november";
  143. break;
  144. }
  145. case 12: {
  146. monthout = "december";
  147. break;
  148. }
  149. }
  150. String sex = "";
  151. switch (Century) {
  152. case 1: {
  153. Year = Year + 1800;
  154. sex += "man";
  155. break;
  156. }
  157. case 3: {
  158. Year = Year + 1900;
  159. sex += "man";
  160. break;
  161. }
  162. case 5: {
  163. Year = Year + 2000;
  164. sex += "man";
  165. break;
  166. }
  167. case 2: {
  168. Year = Year + 1800;
  169. sex += "woman";
  170. break;
  171. }
  172. case 4: {
  173. Year = Year + 1900;
  174. sex += "woman";
  175. break;
  176. }
  177. case 6: {
  178. Year = Year + 2000;
  179. sex += "woman";
  180. break;
  181. }
  182. }
  183. int cheakCentury = wrongCentury ? 1 : 0;
  184. int cheakDay = wrongDay ? 1 : 0;
  185. int cheakMonth = wrongMonth ? 1 : 0;
  186. int cheakLetter = wrongLetter ? 1 : 0;
  187. wrong(cheakCentury, cheakDay, cheakMonth, cheakLetter, cheakLength);
  188. System.out.println("test answer");
  189. int Age = 2019 - Year;
  190. int today = 18;
  191. int currentMonth = 4;
  192. if (Month >= currentMonth && Day > today || Month > currentMonth) {
  193. Age = Age - 1;
  194. }
  195. System.out.println(Year + " " + Month + " " + Day + " " + Century);
  196. System.out.println("Age: " + Age);
  197. System.out.println("Date of birthday: " + Day + " " + monthout + " " + Year);
  198. System.out.println(sex);
  199. }
  200. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement