Greetings to all experts,
I am a newbie here in Java OOP and is struggling in practicing how to code a OO program, using Java. I hope anyone can give me a head start please.
Here is the requirement which i am suppose to complete:
Input
The first line of the input contains an integer N (1 <= N <= 100) denoting the number of people in the group. The next N lines contain the information (name, height in centimeters, and weight in kilograms) of the people in the group.
Output
Output the name of the shortest and tallest people in the group with format:
Suppose A is the shortest and B is the tallest person in the group, then the output will be:
A is the shortest with BMI equals to C.
B is the tallest with BMI equals to D.
where C is the BMI for A and D is the BMI for B. Output the BMI with 2 digit after the decimal point rounded to the nearest integer.
Sample Input
5
Diamond 178 55
Jarod 160 80
Douglas 180 60
Rod 151 48
Joe 178 55
Sample Output
Rod is the shortest with BMI equals to 21.05.
Douglas is the tallest with BMI equals to 18.52.
Thus, I have created 2 classes namely Person and Measurement (main method can be found in here). Below are the codes which i am working on:
import java.util.*;
// create an object called Person that has attribute name, height, weight
class Person {
// declare the attributes
String name;
double height, weight;
// declare the constructor
public Person (double h, double w)
{
height = h;
weight = w;
}
/* use this method to compute the BMI for that person
* PRE-Condition :
* POST-Condition :
*/
public double computeBMI() {
return (weight / height * height);
// implement the BMI formula
}
}
public class Measurement {
public static void main(String[] args) {
// declare the necessary variables
int count;
// declare a Scanner object to read input
Scanner scan = new Scanner(System.in);
// read input and process them accordingly
count = scan.nextInt();
Person.name = scan.nextLine();
Person.h = scan.nextDouble();
Person.w = scan.nextDouble();
// simulate the problem
// output the result
System.out.println(Person.computeBMI);
}
}
Thank you so much for all your guidance.