Advertisement
Guest User

function error

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