public class MainActivity extends AppCompatActivity {
Spinner pregPostWoman, chronicDiseases;
EditText userAge;
Button btnrecommend;
TextView recommendExercise;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
userAge.findViewById(R.id.age);
pregPostWoman.findViewById(R.id.pregnantWoman);
chronicDiseases.findViewById(R.id.croDiseases);
btnrecommend.findViewById(R.id.btnRecommend);
recommendExercise.findViewById(R.id.textRecommend);
ArrayAdapter<CharSequence> adapterPregPostWoman = ArrayAdapter.createFromResource(this, R.array.spinner_choise, android.R.layout.simple_spinner_item);
adapterPregPostWoman.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
pregPostWoman.setAdapter(adapterPregPostWoman);
ArrayAdapter<CharSequence> adapterChronicDiseases = ArrayAdapter.createFromResource(this, R.array.spinner_choise, android.R.layout.simple_spinner_item);
adapterChronicDiseases.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
chronicDiseases.setAdapter(adapterChronicDiseases);
btnrecommend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int age = Integer.parseInt(userAge.getText().toString());
String spinnerPregPostWoman = pregPostWoman.getSelectedItem().toString();
String spinnerChronicDiseases = chronicDiseases.getSelectedItem().toString();
String recommendation = recommendExercise(age, spinnerPregPostWoman, spinnerChronicDiseases);
recommendExercise.setText(recommendation);
}
});
}
private String recommendExercise(int age, String spinnerPregPostWoman, String spinnerChronicDiseases){
String recommendationExercise1 = "";
String recommendationExercise2 = "";
String combination = "";
if (age >= 5 && age <= 17)
{
recommendationExercise1 = "Do exercise 60 minutes per day\n";
recommendationExercise2 = "moderate to vigorous activity or vigorous activity (Running, Swimming, Biking, Jumping Rope)\n" +
"strengthening body (Jumping rope, Push-up, Dancing, Climbing, Aerobic)";
combination = recommendationExercise1 + recommendationExercise2;
}
else if (age >= 18 && age <= 64)
{
if(spinnerPregPostWoman.equals("yes"))
{
combination = "150 minutes moderate activity (Brisk Walking, Tennis Double, Yoga, Gardening)\n" +
"aerobic and muscle - strengthening activities (umping rope, Push-up, Dancing, Climbing, Aerobic)";
}
else if(spinnerPregPostWoman.equals("no"))
{
if(spinnerChronicDiseases.equals("yes"))
{
recommendationExercise1 = "Do functional balance activity (Standing 3 ways, Standing March, Side Step, Sit to Stand Balance)\n";
recommendationExercise2 = "Do 150–300 minutes of moderate-intensity aerobic physical activity (Brisk Walking, Tennis Double, Yoga, Gardening)\n" +
"or 75–150 minutes of vigorous-intensity aerobic physical activity (Running, Swimming, Biking, Jumping Rope)";
combination = recommendationExercise1 + recommendationExercise2;
}
else if(spinnerChronicDiseases.equals("no"))
{
recommendationExercise1 = "Do 150–300 minutes of moderate-intensity aerobic physical activity (Brisk Walking, Tennis Double, Yoga, Gardening)\n" +
"or 75–150 minutes of vigorous-intensity aerobic physical activity (Running, Swimming, Biking, Jumping Rope)";
combination = recommendationExercise1;
}
}
}
else
{
recommendationExercise1 = "No matching exercises found. Please try different preferences.";
combination = recommendationExercise1;
}
return combination;
}
}
I try to make a recommendation of exercise using method if-else like in the code but the code have some problem. I don’t know how to identify it. The input comes from EditText and spinner. Then there is one button to generate the exercise.