Advertisement
Guest User

javaIINend

a guest
Apr 24th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.03 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class Scratch {
  4.  
  5. static void checkLength(String IIN)
  6. {
  7. if(IIN.length() != 12) {
  8. System.out.println("wrong amount of IIN");
  9. System.exit(0);
  10. }
  11. }
  12.  
  13. static void checkLetters(String IIN)
  14. {
  15. boolean Letter = false;
  16. for(int i=0; i<IIN.length(); i++)
  17. {
  18. if(IIN.charAt(i)<'0' || IIN.charAt(i)>'9')
  19. {
  20. System.out.println("Error symbol " + (i+1) + " is letter");
  21. Letter = true;
  22. }
  23. }
  24. if(Letter == true)
  25. {
  26. System.exit(0);
  27. }
  28. }
  29.  
  30. static void checkData(String IIN)
  31. {
  32. String year = IIN.substring(0,2);
  33. String month = IIN.substring(2,4);
  34. String day = IIN.substring(4, 6);
  35. String century = IIN.substring(6, 7);
  36. int Year = Integer.parseInt(year);
  37. int Month = Integer.parseInt(month);
  38. int Day = Integer.parseInt(day);
  39. int Century = Integer.parseInt(century);
  40. boolean checkMonth = false;
  41. boolean checkDay = false;
  42. boolean checkCentury = false;
  43. boolean chekTrueIIN = false;
  44. if(Month > 12 || Month <= 0) // проверка Месяца
  45. {
  46. checkMonth = true;
  47. }
  48. if(Century > 6 || Century <=0) // проверка века и пола
  49. {
  50. checkCentury = true;
  51. }
  52. if(Month == 4 || Month == 6 || Month == 9 || Month == 11) // проверка месяца и дней
  53. {
  54. if(Day>30 || Day <= 0)
  55. {
  56. checkDay = true;
  57. }
  58. }
  59. else
  60. {
  61. if(Day > 31 || Day <= 0)
  62. {
  63. checkDay = true;
  64. }
  65. }
  66. int leapYear = Year%4;
  67. if(leapYear>0 && Month == 2) // проверка високосного года
  68. {
  69. if(Day > 28)
  70. {
  71. checkDay = true;
  72. }
  73. }
  74. if(leapYear == 0 && Month == 2)
  75. {
  76. if(Day > 29)
  77. {
  78. checkDay = true;
  79. }
  80. }
  81. if(Century == 5 && Year > 19 || Century == 6 && Year > 19)
  82. {
  83. chekTrueIIN = true;
  84. System.out.println("in the future invented a time machine?");
  85. }
  86. if(checkMonth == true)
  87. {
  88. System.out.println("Entered wrong month");
  89. }
  90. if(checkDay == true)
  91. {
  92. System.out.println("Entered wrong day");
  93. }
  94. if(checkCentury == true)
  95. {
  96. System.out.println("Entered wrong century");
  97. }
  98. if(checkCentury == true || checkDay == true || checkMonth == true || chekTrueIIN == true)
  99. {
  100. System.exit(0);
  101. }
  102. else
  103. {
  104. information(Year, Month, Day, Century);
  105. }
  106. }
  107.  
  108. static void information(int Year, int Month, int Day, int Century )
  109. {
  110. String monthout = "";
  111. switch(Month)
  112. {
  113. case 1:
  114. {
  115. monthout = "january";
  116. break;
  117. }
  118. case 2:
  119. {
  120. monthout = "febuary";
  121. break;
  122. }
  123. case 3:
  124. {
  125. monthout = "march";
  126. break;
  127. }
  128. case 4:
  129. {
  130. monthout = "april";
  131. break;
  132. }
  133. case 5:
  134. {
  135. monthout = "may";
  136. break;
  137. }
  138. case 6:
  139. {
  140. monthout = "june";
  141. break;
  142. }
  143. case 7:
  144. {
  145. monthout = "jule";
  146. break;
  147. }
  148. case 8:
  149. {
  150. monthout = "august";
  151. break;
  152. }
  153. case 9:
  154. {
  155. monthout = "september";
  156. break;
  157. }
  158. case 10:
  159. {
  160. monthout = "october";
  161. break;
  162. }
  163. case 11:
  164. {
  165. monthout = "november";
  166. break;
  167. }
  168. case 12:
  169. {
  170. monthout = "december";
  171. break;
  172. }
  173. }
  174. String sex = "";
  175. switch(Century)
  176. {
  177. case 1:
  178. {
  179. Year = Year+1800;
  180. sex += "man";
  181. break;
  182. }
  183. case 3:
  184. {
  185. Year = Year+1900;
  186. sex += "man";
  187. break;
  188. }
  189. case 5:
  190. {
  191. Year = Year+2000;
  192. sex += "man";
  193. break;
  194. }
  195. case 2:
  196. {
  197. Year = Year+1800;
  198. sex += "woman";
  199. break;
  200. }
  201. case 4:
  202. {
  203. Year = Year+1900;
  204. sex += "woman";
  205. break;
  206. }
  207. case 6:
  208. {
  209. Year = Year+2000;
  210. sex += "woman";
  211. break;
  212. }
  213. }
  214. int Age = 2019 - Year;
  215. int currentDay = 24;
  216. int currentMonth = 4;
  217. if(Month <= currentMonth && Day < currentDay)
  218. {
  219. Age = Age-1;
  220. }
  221. System.out.println("Age: "+Age);
  222. System.out.println("Date of birthday: "+Day+" "+monthout+" "+Year);
  223. System.out.println(sex);
  224. }
  225.  
  226. public static void main(String[] args)
  227. {
  228. Scanner in = new Scanner(System.in);
  229. String IIN = in.nextLine();
  230. checkLength(IIN);
  231. checkLetters(IIN);
  232. checkData(IIN);
  233. }
  234. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement