Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- class Person {
- // declare the attributes
- private double _weight, _height;
- private String _name;
- // declare the constructor
- public Person() {
- //initialize all attributes to 0.
- }
- public Person(String aName, int aWeight, int aHeight){
- //initialize all attributes to user-defined values
- _name = aName;
- _weight = aWeight;
- _height = aHeight;
- }
- public double computeBMI() {
- // implement the BMI formula
- return _weight * 10000 / (_height * _height);
- }
- }
- class Measurement {
- public static void main(String[] args) {
- // declare the necessary variables
- int n, weight, height, tallest, shortest, tallestSlot, shortestSlot;
- String name, shortestPerson, tallestPerson;
- int[] anArray;
- anArray = new int[101];
- // declare a Scanner object to read input
- Scanner myScanner = new Scanner(System.in);
- // read input and process them accordingly
- n = myScanner.nextInt();
- for (int i = 1; i < n; i++){
- name = myScanner.next();
- height = myScanner.nextInt();
- if (i == 1){
- shortest = height;
- tallest = height;
- shortestPerson = name;
- tallestPerson = name;
- shortestSlot = i;
- tallestSlot = i;
- }
- if (height < shortest){
- shortest = height;
- shortestPerson = name;
- shortestSlot = i;
- }
- if (height > tallest){
- tallest = height;
- tallestPerson = name;
- tallestSlot = i;
- }
- weight = myScanner.nextInt();
- anArray[i] = Person.Person(name, weight, height);
- }
- // simulate the problem
- // output the result
- System.out.println(shortestPerson + " is the shortest with BMI equals to " + anArray[shortestSlot].computeBMI() + ".");
- System.out.println(tallestPerson + " is the tallest with BMI equals to " + anArray[tallestSlot].computeBMI() + ".");
- }
- }
- // line65: cannot find symbol
- // line71, 72: int cannot be dereferenced.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement