-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBMIEncapsulation.java
More file actions
65 lines (48 loc) · 1.47 KB
/
BMIEncapsulation.java
File metadata and controls
65 lines (48 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import java.util.Scanner;
public class BMIEncapsulation {
private String name;
private int age;
private double height;
private double weight;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
public double getWeight() {
return weight;
}
public void setWeight(double weight) {
this.weight = weight;
}
public double calculateBMI() {
return (height - 100) / weight;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
BMIEncapsulation person = new BMIEncapsulation();
System.out.print("Enter name: ");
person.setName(scanner.nextLine());
System.out.print("Enter age: ");
person.setAge(scanner.nextInt());
System.out.print("Enter height (in cm): ");
person.setHeight(scanner.nextDouble());
System.out.print("Enter weight (in kg): ");
person.setWeight(scanner.nextDouble());
double bmi = person.calculateBMI();
System.out.println("The person name is " + person.getName() + " and he/she is " + person.getAge() + " years old and his/her bmi is " + bmi);
}
}