import java.io.*;
import java.util.Scanner;
public class Main
{
{
java.
util.
Scanner s
= new Scanner
(System.
in);
System.
out.
print("年齢を入力してください:"); int age = s.nextInt();
System.
out.
print("BMIを入力してください:"); int bmi = s.nextInt();
System.
out.
print("性別を入力してください(1:男、2:女):"); Sex sex = (s.nextInt() == 1) ? Sex.man : Sex.woman;
System.
out.
print("喫煙しますか?(1:する、2:しない):"); Smoking smoking = (s.nextInt() == 1) ? Smoking.yes : Smoking.no;
System.
out.
print("最高血圧を入力してください:"); int systolic = s.nextInt();
System.
out.
print("最低血圧を入力してください:"); int diastolic = s.nextInt();
int agePoint = Grader.agePoint(age);
int bmiPoint = Grader.bmiPoint(bmi);
int smokingPoint = Grader.smokingPoint(smoking, sex);
int sexPoint = Grader.sexPoint(sex);
int bloodPressurePoint = Grader.bloodPressurePoint(systolic, diastolic);
int totalPoint = agePoint + bmiPoint + smokingPoint + sexPoint + bloodPressurePoint;
CrisisRate rate = Grader.crisisRate(totalPoint);
System.
out.
println("年齢:" + age
+ " " + agePoint
+ "点"); System.
out.
println("BMI:" + bmi
+ " " + bmiPoint
+ "点"); System.
out.
println("性別:" + ((sex
== Sex.
man) ? "男" : "女") + " " + sexPoint
+ "点"); System.
out.
println("喫煙:" + ((smoking
== Smoking.
yes) ? "する" : "しない") + " " + smokingPoint
+ "点"); System.
out.
println("血圧:" + systolic
+ "/" + diastolic
+ " " + bloodPressurePoint
+ "点"); System.
out.
println("合計" + totalPoint
+ "点"); System.
out.
println("10年間に脳卒中を発症する確率は" + rate.
low + "%以上" + rate.
high + "%未満です"); }
}
enum Sex
{
man, woman
}
enum Smoking
{
yes, no
}
class Grader
{
static CrisisRate crisisRate(int point)
{
if (point <= 10)
{
return new CrisisRate(0, 1);
}
else if (point <= 17)
{
return new CrisisRate(1, 2);
}
else if (point <= 22)
{
return new CrisisRate(2, 3);
}
else if (point <= 25)
{
return new CrisisRate(3, 4);
}
else if (point <= 27)
{
return new CrisisRate(4, 5);
}
else if (point <= 29)
{
return new CrisisRate(5, 6);
}
else if (point <= 30)
{
return new CrisisRate(6, 7);
}
else if (point <= 32)
{
return new CrisisRate(7, 8);
}
else if (point <= 33)
{
return new CrisisRate(8, 9);
}
else if (point <= 34)
{
return new CrisisRate(9, 10);
}
else if (point <= 36)
{
return new CrisisRate(10, 12);
}
else if (point <= 39)
{
return new CrisisRate(12, 15);
}
else if (point <= 42)
{
return new CrisisRate(15, 20);
}
else
{
return new CrisisRate(20, 100);
}
}
static int agePoint(int age)
{
if (age < 45)
{
return 0;
}
else if (age < 50)
{
return 5;
}
else if (age < 55)
{
return 6;
}
else if (age < 60)
{
return 12;
}
else if (age < 65)
{
return 16;
}
else if (age < 70)
{
return 19;
}
else
{
}
}
static int smokingPoint(Smoking smoking, Sex sex)
{
switch (smoking)
{
case yes:
switch (sex)
{
case man:
return 4;
case woman:
return 8;
default:
}
case no:
return 0;
default:
}
}
static int sexPoint(Sex sex)
{
switch (sex)
{
case man:
return 6;
case woman:
return 0;
default:
}
}
static int bmiPoint(int bmi)
{
if (bmi < 25)
{
return 0;
}
else if (bmi < 30)
{
return 2;
}
else
{
return 3;
}
}
static int bloodPressurePoint(int systolic, int diastolic)
{
int systolicPoint = systolicBloodPressurePoint(systolic);
int diastolicPoint = diastolicBloodPressurePoint(diastolic);
return (systolicPoint >= diastolicPoint) ? systolicPoint : diastolicPoint;
}
static int systolicBloodPressurePoint(int pressure)
{
if (pressure < 120)
{
return 0;
}
else if (pressure < 130)
{
return 3;
}
else if (pressure < 140)
{
return 6;
}
else if (pressure < 160)
{
return 8;
}
else if (pressure < 180)
{
return 11;
}
else
{
return 13;
}
}
static int diastolicBloodPressurePoint(int pressure)
{
if (pressure < 80)
{
return 0;
}
else if (pressure < 85)
{
return 3;
}
else if (pressure < 90)
{
return 6;
}
else if (pressure < 100)
{
return 8;
}
else if (pressure < 110)
{
return 11;
}
else
{
return 13;
}
}
}
class CrisisRate
{
int low;
int high;
CrisisRate(int low, int high)
{
this.low = low;
this.high = high;
}
}