SHOW:
|
|
- or go back to the newest paste.
| 1 | import java.util.*; | |
| 2 | ||
| 3 | class Person {
| |
| 4 | // declare the attributes | |
| 5 | private double _weight, _height; | |
| 6 | private String _name; | |
| 7 | // declare the constructor | |
| 8 | ||
| 9 | public Person() {
| |
| 10 | //initialize all attributes to 0. | |
| 11 | } | |
| 12 | ||
| 13 | public Person(String aName, int aWeight, int aHeight){
| |
| 14 | //initialize all attributes to user-defined values | |
| 15 | _name = aName; | |
| 16 | _weight = aWeight; | |
| 17 | _height = aHeight; | |
| 18 | } | |
| 19 | ||
| 20 | public double computeBMI() {
| |
| 21 | ||
| 22 | // implement the BMI formula | |
| 23 | return _weight * 10000 / (_height * _height); | |
| 24 | ||
| 25 | } | |
| 26 | ||
| 27 | } | |
| 28 | ||
| 29 | class Measurement {
| |
| 30 | ||
| 31 | public static void main(String[] args) {
| |
| 32 | // declare the necessary variables | |
| 33 | int n, weight, height, tallest, shortest, tallestSlot, shortestSlot; | |
| 34 | String name, shortestPerson, tallestPerson; | |
| 35 | int[] anArray; | |
| 36 | anArray = new int[101]; | |
| 37 | // declare a Scanner object to read input | |
| 38 | Scanner myScanner = new Scanner(System.in); | |
| 39 | ||
| 40 | ||
| 41 | // read input and process them accordingly | |
| 42 | n = myScanner.nextInt(); | |
| 43 | for (int i = 1; i < n; i++){
| |
| 44 | name = myScanner.next(); | |
| 45 | height = myScanner.nextInt(); | |
| 46 | if (i == 1){
| |
| 47 | shortest = height; | |
| 48 | tallest = height; | |
| 49 | shortestPerson = name; | |
| 50 | tallestPerson = name; | |
| 51 | shortestSlot = i; | |
| 52 | tallestSlot = i; | |
| 53 | } | |
| 54 | if (height < shortest){
| |
| 55 | shortest = height; | |
| 56 | shortestPerson = name; | |
| 57 | shortestSlot = i; | |
| 58 | } | |
| 59 | if (height > tallest){
| |
| 60 | tallest = height; | |
| 61 | tallestPerson = name; | |
| 62 | tallestSlot = i; | |
| 63 | } | |
| 64 | weight = myScanner.nextInt(); | |
| 65 | anArray[i] = Person.Person(name, weight, height); | |
| 66 | } | |
| 67 | // simulate the problem | |
| 68 | ||
| 69 | ||
| 70 | // output the result | |
| 71 | System.out.println(shortestPerson + " is the shortest with BMI equals to " + anArray[shortestSlot].computeBMI() + "."); | |
| 72 | System.out.println(tallestPerson + " is the tallest with BMI equals to " + anArray[tallestSlot].computeBMI() + "."); | |
| 73 | ||
| 74 | } | |
| 75 | } | |
| 76 | ||
| 77 | - | // line70: cannot find symbol |
| 77 | + | // line65: cannot find symbol |
| 78 | - | // line76, 77: int cannot be dereferenced. |
| 78 | + | // line71, 72: int cannot be dereferenced. |