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