Я новичок в Java программирование поэтому, пожалуйста, простите мои глупые вопросы,расчет Android сердце риск
Пример, как это: позволяет сказать, что вы 30yo женщина, вы начинаете с -9 баллов. Если ваш общий холестерин равен 180, добавьте 4 очка, если ваш курильщик добавит 8 очков, если ваш холестерин ЛПВП превышает 60, вычтите 1 балл, и если ваше кровяное давление равно 135, добавьте 1 балл. Даю вам результат +3.
Мне сложно понять, как добавить отдельные номера баллов вместе.
Это то, что я пытался до сих пор:
private void calculateForWomen(){
// For Women
// 20–34 years: Minus 7 points. 35–39 years: Minus 3 points.
// 40–44 years: 0 points. 45–49 years: 3 points.
// 50–54 years: 6 points. 55–59 years: 8 points.
// 60–64 years: 10 points. 65–69 years: 12 points.
// 70–74 years: 14 points. 75–79 years: 16 points.
String strIsSmoker = spSmoker.getSelectedItem().toString();
strAge = etAge.getText().toString();
strTotalCholesterol = etTotalCholesterol.getText().toString();
strHDL = etHDL.getText().toString();
strSBP = etSBP.getText().toString();
int age = Integer.valueOf(strAge);
int totalcholesterol = Integer.valueOf(strTotalCholesterol);
int hdl = Integer.valueOf(strHDL);
int sbp = Integer.valueOf(strSBP);
if(age >= 20 || age <= 34 ){ // Minus 7 points
// First point
points = points - 7;
// Second point
if(totalcholesterol <= 160){ // 0 point
points = points + 0;
}
else if(totalcholesterol >= 160 || totalcholesterol <= 199){ // 4 points
points = points + 4;
}
else if(totalcholesterol >= 200 || totalcholesterol <= 239){ // 8 points
points = points + 8;
}
else if(totalcholesterol >= 240 || totalcholesterol <= 279){ // 11 points
points += 11;
}
else if(totalcholesterol >=280){ // 13 points
points += 13;
}
// Third point
if(hdl >= 60) // Minus 1 point
{
points -= 1;
}
else if(hdl >= 50 || hdl <= 59){ // 1 point
points += 1;
}
else if(hdl <= 40){ // 2 points
points += 2;
}
// Fourth point
if(sbp == 120){ // 0 point
points += 0;
}
else if(sbp >= 120 || sbp <= 129){ // 1 point
points += 1;
}
else if(sbp >= 130 || sbp <= 139){ // 2 points
points += 2;
}
else if(sbp >= 140 || sbp <= 159){ // 3 points
points += 3;
}
else if(sbp >= 160){ // 4 points
points += 4;
}
// Fifth point
// 9 points
if(strIsSmoker.equals("Yes")){
points += 9;
} // 0 point
else if(strIsSmoker.equals("No")){
points += 0;
}
totalPoints = points;
String strTotalPoints = String.valueOf(totalPoints);
Toast.makeText(getBaseContext(), "Your score is " + strTotalPoints, Toast.LENGTH_LONG).show();
}
else if(age >= 35 || age <= 39){
// First point
points = points - 3;
// Second point
if(totalcholesterol <= 160){ // 0 point
points = points + 0;
}
else if(totalcholesterol >= 160 || totalcholesterol <= 199){ // 4 points
points = points + 4;
}
else if(totalcholesterol >= 200 || totalcholesterol <= 239){ // 8 points
points = points + 8;
}
else if(totalcholesterol >= 240 || totalcholesterol <= 279){ // 11 points
points += 11;
}
else if(totalcholesterol >=280){ // 13 points
points += 13;
}
// Third point
if(hdl >= 60) // Minus 1 point
{
points -= 1;
}
else if(hdl >= 50 || hdl <= 59){ // 1 point
points += 1;
}
else if(hdl <= 40){ // 2 points
points += 2;
}
// Fourth point
if(sbp == 120){ // 0 point
points += 0;
}
else if(sbp >= 120 || sbp <= 129){ // 1 point
points += 1;
}
else if(sbp >= 130 || sbp <= 139){ // 2 points
points += 2;
}
else if(sbp >= 140 || sbp <= 159){ // 3 points
points += 3;
}
else if(sbp >= 160){ // 4 points
points += 4;
}
// Fifth point
// 9 points
if(strIsSmoker.equals("Yes")){
points += 9;
} // 0 point
else if(strIsSmoker.equals("No")){
points += 0;
}
totalPoints = points;
String strTotalPoints = String.valueOf(totalPoints);
Toast.makeText(getBaseContext(), "Your score is " + strTotalPoints, Toast.LENGTH_LONG).show();
}
else if(age >= 40 || age <= 44){
// First point
points += 0;
// Second point
if(totalcholesterol <= 160){ // 0 point
points += 0;
}
else if(totalcholesterol >= 160 || totalcholesterol <= 199){ // 3 points
points += 3;
}
else if(totalcholesterol >= 200 || totalcholesterol <= 239){ // 6 points
points += 6;
}
else if(totalcholesterol >= 240 || totalcholesterol <= 279){ // 8 points
points += 8;
}
else if(totalcholesterol >=280){ // 10 points
points += 10;
}
// Third point
if(hdl >= 60) // Minus 1 point
{
points -= 1;
}
else if(hdl >= 50 || hdl <= 59){ // 1 point
points += 1;
}
else if(hdl <= 40){ // 2 points
points += 2;
}
// Fourth point
if(sbp == 120){ // 0 point
points += 0;
}
else if(sbp >= 120 || sbp <= 129){ // 1 point
points += 1;
}
else if(sbp >= 130 || sbp <= 139){ // 2 points
points += 2;
}
else if(sbp >= 140 || sbp <= 159){ // 3 points
points += 3;
}
else if(sbp >= 160){ // 4 points
points += 4;
}
// Fifth point
// 7 points
if(strIsSmoker.equals("Yes")){
points += 7;
}
else if(strIsSmoker.equals("No")){
points += 0;
}
totalPoints = points;
String strTotalPoints = String.valueOf(totalPoints);
Toast.makeText(getBaseContext(), "Your score is " + strTotalPoints, Toast.LENGTH_LONG).show();
}
else if(age >= 45 || age <= 49){
// First point
points += 3;
// Second point
if(totalcholesterol <= 160){ // 0 point
points += 0;
}
else if(totalcholesterol >= 160 || totalcholesterol <= 199){ // 3 points
points += 3;
}
else if(totalcholesterol >= 200 || totalcholesterol <= 239){ // 6 points
points += 6;
}
else if(totalcholesterol >= 240 || totalcholesterol <= 279){ // 8 points
points += 8;
}
else if(totalcholesterol >=280){ // 10 points
points += 10;
}
// Third point
if(hdl >= 60) // Minus 1 point
{
points -= 1;
}
else if(hdl >= 50 || hdl <= 59){ // 1 point
points += 1;
}
else if(hdl <= 40){ // 2 points
points += 2;
}
// Fourth point
if(sbp == 120){ // 0 point
points += 0;
}
else if(sbp >= 120 || sbp <= 129){ // 1 point
points += 1;
}
else if(sbp >= 130 || sbp <= 139){ // 2 points
points += 2;
}
else if(sbp >= 140 || sbp <= 159){ // 3 points
points += 3;
}
else if(sbp >= 160){ // 4 points
points += 4;
}
// Fifth point
// 7 points
if(strIsSmoker.equals("Yes")){
points += 7;
}
else if(strIsSmoker.equals("No")){
points += 0;
}
totalPoints = points;
String strTotalPoints = String.valueOf(totalPoints);
Toast.makeText(getBaseContext(), "Your score is " + strTotalPoints, Toast.LENGTH_LONG).show();
}
else if(age >= 50 || age <= 54){
// First point
points += 6;
// Second point
if(totalcholesterol <= 160){ // 0 point
points += 0;
}
else if(totalcholesterol >= 160 || totalcholesterol <= 199){ // 2 points
points += 2;
}
else if(totalcholesterol >= 200 || totalcholesterol <= 239){ // 4 points
points += 4;
}
else if(totalcholesterol >= 240 || totalcholesterol <= 279){ // 5 points
points += 5;
}
else if(totalcholesterol >=280){ // 7 points
points += 7;
}
// Third point
if(hdl >= 60) // Minus 1 point
{
points -= 1;
}
else if(hdl >= 50 || hdl <= 59){ // 1 point
points += 1;
}
else if(hdl <= 40){ // 2 points
points += 2;
}
// Fourth point
if(sbp == 120){ // 0 point
points += 0;
}
else if(sbp >= 120 || sbp <= 129){ // 1 point
points += 1;
}
else if(sbp >= 130 || sbp <= 139){ // 2 points
points += 2;
}
else if(sbp >= 140 || sbp <= 159){ // 3 points
points += 3;
}
else if(sbp >= 160){ // 4 points
points += 4;
}
// Fifth point
// 4 points
if(strIsSmoker.equals("Yes")){
points += 4;
}
else if(strIsSmoker.equals("No")){
points += 0;
}
totalPoints = points;
String strTotalPoints = String.valueOf(totalPoints);
Toast.makeText(getBaseContext(), "Your score is " + strTotalPoints, Toast.LENGTH_LONG).show();
}
else if(age >= 55 | age <= 59){
// First point
points += 8;
// Second point
if(totalcholesterol <= 160){ // 0 point
points += 0;
}
else if(totalcholesterol >= 160 || totalcholesterol <= 199){ // 2 points
points += 2;
}
else if(totalcholesterol >= 200 || totalcholesterol <= 239){ // 4 points
points += 4;
}
else if(totalcholesterol >= 240 || totalcholesterol <= 279){ // 5 points
points += 5;
}
else if(totalcholesterol >=280){ // 7 points
points += 7;
}
// Third point
if(hdl >= 60) // Minus 1 point
{
points -= 1;
}
else if(hdl >= 50 || hdl <= 59){ // 1 point
points += 1;
}
else if(hdl <= 40){ // 2 points
points += 2;
}
// Fourth point
if(sbp == 120){ // 0 point
points += 0;
}
else if(sbp >= 120 || sbp <= 129){ // 1 point
points += 1;
}
else if(sbp >= 130 || sbp <= 139){ // 2 points
points += 2;
}
else if(sbp >= 140 || sbp <= 159){ // 3 points
points += 3;
}
else if(sbp >= 160){ // 4 points
points += 4;
}
// Fifth point
// 4 points
if(strIsSmoker.equals("Yes")){
points += 4;
}
else if(strIsSmoker.equals("No")){
points += 0;
}
totalPoints = points;
String strTotalPoints = String.valueOf(totalPoints);
Toast.makeText(getBaseContext(), "Your score is " + strTotalPoints, Toast.LENGTH_LONG).show();
}
else if(age >= 60 || age <= 64){
// First point
points += 10;
// Second point
if(totalcholesterol <= 160){ // 0 point
points += 0;
}
else if(totalcholesterol >= 160 || totalcholesterol <= 199){ // 1 points
points += 1;
}
else if(totalcholesterol >= 200 || totalcholesterol <= 239){ // 2 points
points += 2;
}
else if(totalcholesterol >= 240 || totalcholesterol <= 279){ // 3 points
points += 3;
}
else if(totalcholesterol >=280){ // 4 points
points += 4;
}
// Third point
if(hdl >= 60) // Minus 1 point
{
points -= 1;
}
else if(hdl >= 50 || hdl <= 59){ // 1 point
points += 1;
}
else if(hdl <= 40){ // 2 points
points += 2;
}
// Fourth point
if(sbp == 120){ // 0 point
points += 0;
}
else if(sbp >= 120 || sbp <= 129){ // 1 point
points += 1;
}
else if(sbp >= 130 || sbp <= 139){ // 2 points
points += 2;
}
else if(sbp >= 140 || sbp <= 159){ // 3 points
points += 3;
}
else if(sbp >= 160){ // 4 points
points += 4;
}
// Fifth point
// 2 points
if(strIsSmoker.equals("Yes")){
points += 2;
}
else if(strIsSmoker.equals("No")){
points += 0;
}
totalPoints = points;
String strTotalPoints = String.valueOf(totalPoints);
Toast.makeText(getBaseContext(), "Your score is " + strTotalPoints, Toast.LENGTH_LONG).show();
}
else if(age >= 65 || age <= 69){
// First point
points += 12;
// Second point
if(totalcholesterol <= 160){ // 0 point
points += 0;
}
else if(totalcholesterol >= 160 || totalcholesterol <= 199){ // 1 points
points += 1;
}
else if(totalcholesterol >= 200 || totalcholesterol <= 239){ // 2 points
points += 2;
}
else if(totalcholesterol >= 240 || totalcholesterol <= 279){ // 3 points
points += 3;
}
else if(totalcholesterol >=280){ // 4 points
points += 4;
}
// Third point
if(hdl >= 60) // Minus 1 point
{
points -= 1;
}
else if(hdl >= 50 || hdl <= 59){ // 1 point
points += 1;
}
else if(hdl <= 40){ // 2 points
points += 2;
}
// Fourth point
if(sbp == 120){ // 0 point
points += 0;
}
else if(sbp >= 120 || sbp <= 129){ // 1 point
points += 1;
}
else if(sbp >= 130 || sbp <= 139){ // 2 points
points += 2;
}
else if(sbp >= 140 || sbp <= 159){ // 3 points
points += 3;
}
else if(sbp >= 160){ // 4 points
points += 4;
}
// Fifth point
// 2 points
if(strIsSmoker.equals("Yes")){
points += 2;
}
else if(strIsSmoker.equals("No")){
points += 0;
}
totalPoints = points;
String strTotalPoints = String.valueOf(totalPoints);
Toast.makeText(getBaseContext(), "Your score is " + strTotalPoints, Toast.LENGTH_LONG).show();
}
else if(age >= 70 || age <= 74){
// First point
points += 14;
// Second point
if(totalcholesterol <= 160){ // 0 point
points += 0;
}
else if(totalcholesterol >= 160 || totalcholesterol <= 199){ // 1 points
points += 1;
}
else if(totalcholesterol >= 200 || totalcholesterol <= 239){ // 1 points
points += 1;
}
else if(totalcholesterol >= 240 || totalcholesterol <= 279){ // 2 points
points += 2;
}
else if(totalcholesterol >=280){ // 2 points
points += 2;
}
// Third point
if(hdl >= 60) // Minus 1 point
{
points -= 1;
}
else if(hdl >= 50 || hdl <= 59){ // 1 point
points += 1;
}
else if(hdl <= 40){ // 2 points
points += 2;
}
// Fourth point
if(sbp == 120){ // 0 point
points += 0;
}
else if(sbp >= 120 || sbp <= 129){ // 1 point
points += 1;
}
else if(sbp >= 130 || sbp <= 139){ // 2 points
points += 2;
}
else if(sbp >= 140 || sbp <= 159){ // 3 points
points += 3;
}
else if(sbp >= 160){ // 4 points
points += 4;
}
// Fifth point
// 1 point
if(strIsSmoker.equals("Yes")){
points += 1;
}
else if(strIsSmoker.equals("No")){
points += 0;
}
totalPoints = points;
String strTotalPoints = String.valueOf(totalPoints);
Toast.makeText(getBaseContext(), "Your score is " + strTotalPoints, Toast.LENGTH_LONG).show();
}
else if(age >= 75 || age <= 79){
// First point
points += 16;
// Second point
if(totalcholesterol <= 160){ // 0 point
points += 0;
}
else if(totalcholesterol >= 160 || totalcholesterol <= 199){ // 1 points
points += 1;
}
else if(totalcholesterol >= 200 || totalcholesterol <= 239){ // 1 points
points += 1;
}
else if(totalcholesterol >= 240 || totalcholesterol <= 279){ // 2 points
points += 2;
}
else if(totalcholesterol >=280){ // 2 points
points += 2;
}
// Third point
if(hdl >= 60) // Minus 1 point
{
points -= 1;
}
else if(hdl >= 50 || hdl <= 59){ // 1 point
points += 1;
}
else if(hdl <= 40){ // 2 points
points += 2;
}
// Fourth point
if(sbp == 120){ // 0 point
points += 0;
}
else if(sbp >= 120 || sbp <= 129){ // 1 point
points += 1;
}
else if(sbp >= 130 || sbp <= 139){ // 2 points
points += 2;
}
else if(sbp >= 140 || sbp <= 159){ // 3 points
points += 3;
}
else if(sbp >= 160){ // 4 points
points += 4;
}
// Fifth point
// 1 point
if(strIsSmoker.equals("Yes")){
points += 1;
}
else if(strIsSmoker.equals("No")){
points += 0;
}
totalPoints = points;
String strTotalPoints = String.valueOf(totalPoints);
Toast.makeText(getBaseContext(), "Your score is " + strTotalPoints, Toast.LENGTH_LONG).show();
}
}
Если кто-то может мне помочь оптимизировать свой код, я бы с удовольствием оценит. Заранее спасибо!
ОБНОВЛЕНО: Когда я пытаюсь выбрать другой возраст (40+), ответ, который я получил, неверен.
Вместо того, чтобы через мили кода, почему бы вам не рассказать нам где ваша проблема? – ElefantPhace
[SSCCE] (http://sscce.org/), пожалуйста. – 2013-03-02 17:56:19
@ElefantPhace, как я уже сказал, я бы хотел оптимизировать свой код, если бы вы могли мне помочь. –