kfaghih
جمعه 19 تیر 1394, 19:00 عصر
با سلام خدمت اساتید محترم
من به تازگی شروع به یادگیری زبان برنامه نویسی جاوا کردم و برنامه مبتدی نوشتم که کد آن در زیر آمده است
import java.text.DecimalFormat;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class NormalWeightCalculator {
public static void main(String[] args) {
do{
Scanner mscanner =new Scanner (System.in);
String ages =JOptionPane.showInputDialog("How old are you.\"at least 19\"");
double age =0;
do{
age =Double.parseDouble(ages);
if (age>=19){break;}
String agens = "To use this program you must be at least 19 years old.Please enter your age again.";
if(age<19){ JOptionPane.showMessageDialog(null,
agens );
continue;}
}
while(true);
String weights = JOptionPane.showInputDialog("Please enter youre weight.\"Kg\"");
double weightd =Double.parseDouble(weights);
String staturess = JOptionPane.showInputDialog("Please enter your height\"cm\"");
double staturecm =Double.parseDouble(staturess);
double staturem = staturecm/100;
double statures = staturem*staturem;
double bmi=0 ;
if (age >=19 &&age <=24){bmi = 22;}
if (age >=25 && age <=34){bmi = 23;}
if (age >= 35&& age <=44){bmi = 24;}
if (age >=45 && age <=54){bmi = 25;}
if (age >=55&&age <=64){bmi=26;}
if (age >65){bmi = 27;}
double nw = bmi*statures;
double ew =0;
String ewt = null;
DecimalFormat nwf = new DecimalFormat("#.00");
String nwfr =nwf.format(nw);
String bmir2 ="Youre normal weight in"+nwfr+"Kg";
if(nw>weightd){ew=nw-weightd; ewt ="And you have"+ew+"Kg underweight";}
else if(nw<weightd){ew=weightd-nw; ewt = "And you have"+ew+"Kg overweight";}
else {ewt =bmir2+"and youre weight is normal";}
String bmir ="Youre normal weight is"+nwfr+"Kg";
JOptionPane.showMessageDialog(null,
bmir + ewt );
String eors =("If you want reapeat app Type \"1\"and enter and if you wand exit app type \"2\" and Enter.");
double eor = Double.parseDouble(eors);
if (eor ==1){continue;}
if(eor==2){break;}
}
while(true);
}
}
اما هنگام اشتباه وارد کردن داده توسط کاربر در حلقه می ماند و دجار مشکل می شود از شما خواهشمندم بنده را راهنمایی کنید
من به تازگی شروع به یادگیری زبان برنامه نویسی جاوا کردم و برنامه مبتدی نوشتم که کد آن در زیر آمده است
import java.text.DecimalFormat;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class NormalWeightCalculator {
public static void main(String[] args) {
do{
Scanner mscanner =new Scanner (System.in);
String ages =JOptionPane.showInputDialog("How old are you.\"at least 19\"");
double age =0;
do{
age =Double.parseDouble(ages);
if (age>=19){break;}
String agens = "To use this program you must be at least 19 years old.Please enter your age again.";
if(age<19){ JOptionPane.showMessageDialog(null,
agens );
continue;}
}
while(true);
String weights = JOptionPane.showInputDialog("Please enter youre weight.\"Kg\"");
double weightd =Double.parseDouble(weights);
String staturess = JOptionPane.showInputDialog("Please enter your height\"cm\"");
double staturecm =Double.parseDouble(staturess);
double staturem = staturecm/100;
double statures = staturem*staturem;
double bmi=0 ;
if (age >=19 &&age <=24){bmi = 22;}
if (age >=25 && age <=34){bmi = 23;}
if (age >= 35&& age <=44){bmi = 24;}
if (age >=45 && age <=54){bmi = 25;}
if (age >=55&&age <=64){bmi=26;}
if (age >65){bmi = 27;}
double nw = bmi*statures;
double ew =0;
String ewt = null;
DecimalFormat nwf = new DecimalFormat("#.00");
String nwfr =nwf.format(nw);
String bmir2 ="Youre normal weight in"+nwfr+"Kg";
if(nw>weightd){ew=nw-weightd; ewt ="And you have"+ew+"Kg underweight";}
else if(nw<weightd){ew=weightd-nw; ewt = "And you have"+ew+"Kg overweight";}
else {ewt =bmir2+"and youre weight is normal";}
String bmir ="Youre normal weight is"+nwfr+"Kg";
JOptionPane.showMessageDialog(null,
bmir + ewt );
String eors =("If you want reapeat app Type \"1\"and enter and if you wand exit app type \"2\" and Enter.");
double eor = Double.parseDouble(eors);
if (eor ==1){continue;}
if(eor==2){break;}
}
while(true);
}
}
اما هنگام اشتباه وارد کردن داده توسط کاربر در حلقه می ماند و دجار مشکل می شود از شما خواهشمندم بنده را راهنمایی کنید