//HealthApp //final boolean DEBUG_MODE = true; final boolean DEBUG_MODE = false; private PersonalData pd; void setup(){ if (DEBUG_MODE == true){ println("<> setup"); noLoop(); size(50,50); testPersonalData(); } else { println("<> setup"); size(200,100); pd = new PersonalData(); } } void draw(){ if (DEBUG_MODE == true){ println("<> draw"); } else { println("<> draw"); background(204); drawManShape(); drawWeightSign(); drawWeightUpButton(); drawWeightDownButton(); drawWeight(); drawHeightSign(); drawHeightUpButton(); drawHeightDownButton(); drawHeight(); drawBMI(); drawCategory(); } } void drawManShape(){ if (pd.getSex().equals("MALE")){ fill(0,0,255); } else if (pd.getSex().equals("FEMALE")){ fill(255,0,0); } else { fill(1); } ellipse(50,30,20,20); fill(255); line(50,40,50,70); line(50,70,30,80); line(50,70,70,80); line(25,50,75,50); } void drawWeightSign(){ fill(0); text("Weight",90,15); fill(255); } void drawWeightUpButton(){ rect(100,25,25,25); fill(0); text("UP",105,40); fill(255); } void drawWeightDownButton(){ rect(100,50,25,25); fill(0); text("DN",105,65); fill(255); } void drawWeight(){ fill(0); text(String.valueOf(pd.getYourWeight()),105,95); fill(255); } void drawHeightSign(){ fill(0); text("Height",140,15); fill(255); } void drawHeightUpButton(){ rect(150,25,25,25); fill(0); text("UP",155,40); fill(255); } void drawHeightDownButton(){ rect(150,50,25,25); fill(0); text("DN",155,65); fill(255); } void drawHeight(){ fill(0); text(String.valueOf(pd.getYourHeight()),155,95); fill(255); } void drawBMI(){ fill(0); text("BMI = " + String.valueOf((int)pd.getBMI()),15,20); fill(255); } void drawCategory(){ fill(0); text("Category = " + String.valueOf((int)pd.getCategory()),15,95); fill(255); } void mousePressed(){ //体重ボタン if ( (100 < mouseX) & (mouseX < 125) & (25 < mouseY) & (mouseY < 50) ){ //体重UPボタンが押された double temp = pd.getYourWeight(); temp = temp + 1; pd.setYourWeight(temp); } if ( (100 < mouseX) & (mouseX < 125) & (50 < mouseY) & (mouseY < 75) ){ //体重DOWNボタンが押された double temp = pd.getYourWeight(); temp = temp - 1; pd.setYourWeight(temp); } //身長ボタン if ( (150 < mouseX) & (mouseX < 175) & (25 < mouseY) & (mouseY < 50) ){ //身長UPボタンが押された double temp = pd.getYourHeight(); temp = temp + 1; pd.setYourHeight(temp); } if ( (150 < mouseX) & (mouseX < 175) & (50 < mouseY) & (mouseY < 75) ){ //身長DOWNボタンが押された double temp = pd.getYourHeight(); temp = temp - 1; pd.setYourHeight(temp); } //顔、性別変更 if ( (40 < mouseX) & (mouseX < 60) & (20 < mouseY) & (mouseY < 40) ){ //顔がクリックされた String temp = pd.getSex(); if (temp.equals("MALE")) { pd.setSex("FEMALE"); } else if (temp.equals("FEMALE")){ pd.setSex("MALE"); } else { pd.setSex("NONE"); } } } void testPersonalData(){ PersonalData pd = new PersonalData("FEMALE",30, 50,165,true); assert pd.getSex().equals("FEMALE") : "Error"; assert pd.getAge() == 30 : "Error"; assert pd.getYourWeight() == 50 : "Error"; assert pd.getYourHeight() == 165 : "Error"; //assert pd.isAthlete() == false : "Error"; assert pd.isAthlete() == true : "Error"; assert (18.3 < pd.getBMI()) & (pd.getBMI() < 18.4) : "Error"; assert pd.getCategory() == -1 : "Error"; pd = new PersonalData("HOGE",25,80,170,false); assert pd.getSex().equals("NONE") : "Error"; //なにもしない pd = new PersonalData(); assert pd.getSex().equals("MALE") : "Error"; assert pd.getAge() == 17 : "Error"; assert pd.getYourWeight() == 70 : "Error"; assert pd.getYourHeight() == 170 : "Error"; assert pd.isAthlete() == false : "Error"; //性別テスト pd = new PersonalData("MALE",30, 50,165,true); assert pd.getSex().equals("MALE") : "Error"; pd = new PersonalData("FEMALE",30, 50,165,true); assert pd.getSex().equals("FEMALE") : "Error"; pd = new PersonalData("FUGA",30, 50,165,true); assert pd.getSex().equals("NONE") : "Error"; assert pd.setSex("MALE").equals("MALE") : "Error"; assert pd.setSex("FEMALE").equals("FEMALE") : "Error"; assert pd.setSex("FUGAGA").equals("NONE") : "Error"; //年齢テスト 負の値から正の値の範囲オーバーまで for( int i = -5; i < 120; ++i ){ pd = new PersonalData("MALE",i, 50,165,true); if (i < 16) { assert pd.getAge() == 17 : "Error"; } else if (( 16 <= i ) & ( i <= 110 )) { assert pd.getAge() == i : "Error"; } else { assert pd.getAge() == 17 : "Error"; } } //体重テスト for( int i = -5; i < 170; ++i ){ pd = new PersonalData("MALE",30,i,165,true); if (i < 30) { assert pd.getYourWeight() == 70 : "Error"; } else if (( 30 <= i ) & ( i <= 150 )) { assert pd.getYourWeight() == i : "Error"; } else { assert pd.getYourWeight() == 70 : "Error"; } } //身長テスト for( int i = -5; i < 250; ++i ){ pd = new PersonalData("MALE",30,70,i,true); if (i < 100) { assert pd.getYourHeight() == 170 : "Error"; } else if (( 100 <= i ) & ( i <= 200 )) { assert pd.getYourHeight() == i : "Error"; } else { assert pd.getYourHeight() == 170 : "Error"; } } //体重・身長のセットメソッドテスト for( int i = -5; i < 170; ++i ){ pd.setYourWeight(i); if (i < 30) { assert pd.getYourWeight() == 70 : "Error"; } else if (( 30 <= i ) & ( i <= 150 )) { assert pd.getYourWeight() == i : "Error"; } else { assert pd.getYourWeight() == 70 : "Error"; } } for( int i = -5; i < 250; ++i ){ pd.setYourHeight(i); if (i < 100) { assert pd.getYourHeight() == 170 : "Error"; } else if (( 100 <= i ) & ( i <= 200 )) { assert pd.getYourHeight() == i : "Error"; } else { assert pd.getYourHeight() == 170 : "Error"; } } }