|
BMI Calculator Project - 7 points
To be submitted online - Due Wednesday (11-2)
by beginning of class.
Create a BMI (Body Mass Index) Calculator, that will display the
persons BMI index and also a determination if the person is overweight,
underweight, obese or normal. Use this for reference on the calculations. Use the math class to square. Your finished project will look a bit like this.
BMI Categories:
- * Underweight = <18.5
* Normal weight = 18.5-24.9
* Overweight = 25-29.9
* Obesity = BMI of 30 or greater
Create a class called BMICalculator (use SimpleExample
as starter code). You are going to have a gui that is going to have
3 textfields for input (for feet,inches, weight) and then 1 button
(for calculate) and 1 textfield for output.
To read a field (say inchesField), you would call the Integer.parseInt
method below
String inchesText=inchesField.getText();
int inches=Integer.parseInt(inchesText); //this converts
the string to an int
You must use labels like below:
JLabel heightLabel = new JLabel ("Enter height");
screen.add (heightLabel);
EXTRA CREDIT: (advanced most do at least 2, hopefully some will try all four)
- Round BMI to 2 or 3 decimals. See here.
- Draw a figure of the person after
they have put in their information. This will all take place in
the paint method. You will modify it so that you are drawing a
person there. You will draw them in much the same way you did
before g.drawOval (..). You will take info about their height
and weight to expand or shrink them. Have it be green if the person
is classified as normal. Blue if they are overweight, black if
obese, and red if underweight (by using the bmi number you calculated
earlier).
- So you want to access graphics in BMI Calculator you might say:
- Graphics g=getGraphics();
- now you can say g.drawLine(.... or anything to g
- Use sliders instead for weight and height (see here)
- Use pulldown to choose male female and then show a graphic of what they look like:
Rubric:
This is worth 7points
- 1 point - indenting and variable names
- 1 point - atleast 2 comments throughout your code explaining the action
- 2 points - gui set up appropriately
- labels (.5)
- order (.5)
- all fields (1)
- 2 points - bmi calculated correctly
- getting field and values correctly (.5)
- doubles used when necessary (.5)
- calculations done correctly (1)
- 1 point - bmi spit out with right comment
|