fork download
  1. import java.io.*;
  2. import java.util.Scanner;
  3.  
  4. public class Main
  5. {
  6.  
  7. public static void main(String[] args) throws IOException
  8. {
  9. java.util.Scanner s = new Scanner(System.in);
  10.  
  11. System.out.print("年齢を入力してください:");
  12. int age = s.nextInt();
  13.  
  14. System.out.print("BMIを入力してください:");
  15. int bmi = s.nextInt();
  16.  
  17. System.out.print("性別を入力してください(1:男、2:女):");
  18. Sex sex = (s.nextInt() == 1) ? Sex.man : Sex.woman;
  19.  
  20. System.out.print("喫煙しますか?(1:する、2:しない):");
  21. Smoking smoking = (s.nextInt() == 1) ? Smoking.yes : Smoking.no;
  22.  
  23. System.out.print("最高血圧を入力してください:");
  24. int systolic = s.nextInt();
  25.  
  26. System.out.print("最低血圧を入力してください:");
  27. int diastolic = s.nextInt();
  28.  
  29. int agePoint = Grader.agePoint(age);
  30. int bmiPoint = Grader.bmiPoint(bmi);
  31. int smokingPoint = Grader.smokingPoint(smoking, sex);
  32. int sexPoint = Grader.sexPoint(sex);
  33. int bloodPressurePoint = Grader.bloodPressurePoint(systolic, diastolic);
  34.  
  35. int totalPoint = agePoint + bmiPoint + smokingPoint + sexPoint + bloodPressurePoint;
  36. CrisisRate rate = Grader.crisisRate(totalPoint);
  37.  
  38. System.out.println("年齢:" + age + " " + agePoint + "点");
  39. System.out.println("BMI:" + bmi + " " + bmiPoint + "点");
  40. System.out.println("性別:" + ((sex == Sex.man) ? "男" : "女") + " " + sexPoint + "点");
  41. System.out.println("喫煙:" + ((smoking == Smoking.yes) ? "する" : "しない") + " " + smokingPoint + "点");
  42. System.out.println("血圧:" + systolic + "/" + diastolic + " " + bloodPressurePoint + "点");
  43. System.out.println("合計" + totalPoint + "点");
  44. System.out.println("10年間に脳卒中を発症する確率は" + rate.low + "%以上" + rate.high + "%未満です");
  45. }
  46. }
  47.  
  48. enum Sex
  49. {
  50. man, woman
  51. }
  52.  
  53. enum Smoking
  54. {
  55. yes, no
  56. }
  57.  
  58. class Grader
  59. {
  60. static CrisisRate crisisRate(int point)
  61. {
  62. if (point <= 10)
  63. {
  64. return new CrisisRate(0, 1);
  65. }
  66. else if (point <= 17)
  67. {
  68. return new CrisisRate(1, 2);
  69. }
  70. else if (point <= 22)
  71. {
  72. return new CrisisRate(2, 3);
  73. }
  74. else if (point <= 25)
  75. {
  76. return new CrisisRate(3, 4);
  77. }
  78. else if (point <= 27)
  79. {
  80. return new CrisisRate(4, 5);
  81. }
  82. else if (point <= 29)
  83. {
  84. return new CrisisRate(5, 6);
  85. }
  86. else if (point <= 30)
  87. {
  88. return new CrisisRate(6, 7);
  89. }
  90. else if (point <= 32)
  91. {
  92. return new CrisisRate(7, 8);
  93. }
  94. else if (point <= 33)
  95. {
  96. return new CrisisRate(8, 9);
  97. }
  98. else if (point <= 34)
  99. {
  100. return new CrisisRate(9, 10);
  101. }
  102. else if (point <= 36)
  103. {
  104. return new CrisisRate(10, 12);
  105. }
  106. else if (point <= 39)
  107. {
  108. return new CrisisRate(12, 15);
  109. }
  110. else if (point <= 42)
  111. {
  112. return new CrisisRate(15, 20);
  113. }
  114. else
  115. {
  116. return new CrisisRate(20, 100);
  117. }
  118. }
  119.  
  120. static int agePoint(int age)
  121. {
  122. if (age < 45)
  123. {
  124. return 0;
  125. }
  126. else if (age < 50)
  127. {
  128. return 5;
  129. }
  130. else if (age < 55)
  131. {
  132. return 6;
  133. }
  134. else if (age < 60)
  135. {
  136. return 12;
  137. }
  138. else if (age < 65)
  139. {
  140. return 16;
  141. }
  142. else if (age < 70)
  143. {
  144. return 19;
  145. }
  146. else
  147. {
  148. throw new RuntimeException("invalid age");
  149. }
  150. }
  151.  
  152. static int smokingPoint(Smoking smoking, Sex sex)
  153. {
  154. switch (smoking)
  155. {
  156. case yes:
  157. switch (sex)
  158. {
  159. case man:
  160. return 4;
  161. case woman:
  162. return 8;
  163. default:
  164. throw new RuntimeException("invalid sex");
  165. }
  166. case no:
  167. return 0;
  168. default:
  169. throw new RuntimeException("invaild smoking");
  170. }
  171. }
  172.  
  173. static int sexPoint(Sex sex)
  174. {
  175. switch (sex)
  176. {
  177. case man:
  178. return 6;
  179. case woman:
  180. return 0;
  181. default:
  182. throw new RuntimeException("invalid sex");
  183. }
  184. }
  185.  
  186. static int bmiPoint(int bmi)
  187. {
  188. if (bmi < 25)
  189. {
  190. return 0;
  191. }
  192. else if (bmi < 30)
  193. {
  194. return 2;
  195. }
  196. else
  197. {
  198. return 3;
  199. }
  200. }
  201.  
  202. static int bloodPressurePoint(int systolic, int diastolic)
  203. {
  204. int systolicPoint = systolicBloodPressurePoint(systolic);
  205. int diastolicPoint = diastolicBloodPressurePoint(diastolic);
  206. return (systolicPoint >= diastolicPoint) ? systolicPoint : diastolicPoint;
  207. }
  208.  
  209. static int systolicBloodPressurePoint(int pressure)
  210. {
  211. if (pressure < 120)
  212. {
  213. return 0;
  214. }
  215. else if (pressure < 130)
  216. {
  217. return 3;
  218. }
  219. else if (pressure < 140)
  220. {
  221. return 6;
  222. }
  223. else if (pressure < 160)
  224. {
  225. return 8;
  226. }
  227. else if (pressure < 180)
  228. {
  229. return 11;
  230. }
  231. else
  232. {
  233. return 13;
  234. }
  235. }
  236.  
  237. static int diastolicBloodPressurePoint(int pressure)
  238. {
  239. if (pressure < 80)
  240. {
  241. return 0;
  242. }
  243. else if (pressure < 85)
  244. {
  245. return 3;
  246. }
  247. else if (pressure < 90)
  248. {
  249. return 6;
  250. }
  251. else if (pressure < 100)
  252. {
  253. return 8;
  254. }
  255. else if (pressure < 110)
  256. {
  257. return 11;
  258. }
  259. else
  260. {
  261. return 13;
  262. }
  263. }
  264. }
  265.  
  266. class CrisisRate
  267. {
  268. int low;
  269. int high;
  270.  
  271. CrisisRate(int low, int high)
  272. {
  273. this.low = low;
  274. this.high = high;
  275. }
  276. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty