# Calculate BMR program

Sarah Tod
Greenhorn
Posts: 20
Hi All,

My home work is: Need to calculate how many bars of choco to maintain woman & man's BMR. See my program below. I want to change the final output without so many decimal points but round it up or you have better string format to advise me. Been stressed with this & another for past 2 nights. Please cut me some slack, i have no programming background. Please also try not to be curt by asking me to unplug my computer & write it on a piece of paper better, as suggested from a 'friendly' programming green horn from a previous post. I am not asking you to do my homework either, just guidance or examples. Thank you. I also understand that there are formats for strings, substring, characters etc. Just don't know how to use them correctly. Thank you.

Out put is: Enter weight in lbs:
118
Enter height in inches:
5.5
Enter age in years:
33
BMR for woman is: 1033.15
BMR for man is: 655.95
A typical Chocolate Bar contains about 230 calories
No. of Chocolate Bars consumed to maintain your weight:
4.491956521739131
2.8519565217391305

Saif Asif
Ranch Hand
Posts: 440
Hello Sarah ,

Use Math.round( Double ) to round it off to the nearest 0.5 .

The above code will always return a whole number.

Balaguru Gupta
Greenhorn
Posts: 10
Try replacing your code like this

DecimalFormat df = new DecimalFormat("###.##");
System.out.println(Double.valueOf(df.format(BMRw / choco)));
System.out.println(Double.valueOf(df.format(BMRm / choco)));

From the above you will get the output in this format "10.00 or 10.11" etc, no matter how many digits you have after the decimal point

Cheerz mate

Campbell Ritchie
Sheriff
Posts: 50175
79
Why are you using DecimalFormat? It is much easier to use the % tags, and they obviate the need for rounding, too.

Sarah Tod
Greenhorn
Posts: 20
I have not learnt the Decimal Format, therefore, i don't think i can use it for this exercise. The % format we just touched. Let me try it.
Can i use System.out.println(BMRw / choco + "%2.f"); ?

fred rosenberger
lowercase baba
Bartender
Posts: 12196
35
Sarah Tod wrote:Can i use System.out.println(BMRw / choco + "%2.f"); ?

What happened when you tried it?

Campbell Ritchie
Sheriff
Posts: 50175
79
Go through this Java Tutorials section until you find the section about formatting print output.

Sarah Tod
Greenhorn
Posts: 20
Came out nothing. What's wrong with it?

Campbell Ritchie
Sheriff
Posts: 50175
79
What came out nothing? You need to tell us the details before we can help.

fred rosenberger
lowercase baba
Bartender
Posts: 12196
35
Sarah Tod wrote:Came out nothing. What's wrong with it?

We don't do that. We will help you figure it out yourself, but nobody here is going to just give you an answer.

"Came out nothing" - so...it printed nothing? no text of any kind? you saw this:
c:\java BMR
c:\

It didn't ask you to enter a weight or height?

Then something else is going on....

or DID it come out with SOMETHING, just not what you WANTED?

Programming requires you to be extremely precise in what you say. We can assume we know what you mean, but there is almost a 100% certainty we'd be wrong. So most of us won't bother. Unless you tell us what happened, and what you expected to happen, there is nothing we can do.

Further...you've been given 3-4 suggestions on what to change. You have probably implemented some of them...but unless we can see your current code you are running, we have no way to know what it is doing.

Sarah Tod
Greenhorn
Posts: 20
Thank you for your help. I resolved it. However, i find that there are too many comments vs showing samples from most people. Not exactly helpful. I do some how believe geeks have low EQ now.

Jeff Verdegan
Bartender
Posts: 6109
6
Sarah Tod wrote:Thank you for your help. I resolved it. However, i find that there are too many comments vs showing samples from most people. Not exactly helpful.

This site is intended to guide you toward finding your own solution. Often times that consists of explaining an approach rather than showing code. In some cases, it may be useful to show an example that's similar to what you're trying to do, and then let you figure out how to adapt it to your specific case. However, in most cases, you're given enough information about the nature of the approach that you can use that to search for examples yourself.

There's a strong philosophy here of giving you just enough information to get you pointed in the right direction, and that's what some of the posts in this thread are doing. The ones that provide code for you to copy and paste are the least helpful.

I do some how believe geeks have low EQ now.

Comments like that are personal attacks, and will, at the very least, discourage people from helping you. Continuing to make those kinds of remarks will get your account locked.