Skip to content
Advertisement

How to implement Body Mass Index (BMI)in Java

My problem is how can I implement without the Scanner method and with Math.round and Math.pow?

Here is my code:

JavaScript

My another idea was It is only for a certain value. In my case with a weight of 75.0 and size 178.0

JavaScript

Advertisement

Answer

It’s up to developer to choose how to initialize parameters.
If don’t want to use scanner the simple way is just add directly.
Initialize can also come from various data-sources: database, file (xml,text), web-service, etc.
For school purpose maybe you could try to build a BMI class and use constructor to pass whatever parameters may want.
Advantage to have a constructor with parameters is that you can build various BMI instances with different result(based on params), not just have only 1 result in for all the class-instances (due to the fact the input is the same).

eg:

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement