public class StudentTest {
public static void main(String[] args) {
// 调用空参!
sop(new Student());
// 创建实例对象!
Student sd = new Student(20151001, "张三", "男", 178, 75, "1980-01-01");
sop(sd);
sop("BMI指标:" + sd.getBmi());
}
private static void sop(Object obj) {
System.out.println(obj);
}
}
class Student {
private int sno;
private String sname;
private String sex;
private double hight;
private double weight;
private String brithDate;
public Student() {
}
public Student(int sno, String sname, String sex, double hight, double weight, String brithDate) {
super();
this.sno = sno;
this.sname = sname;
this.sex = sex;
this.hight = hight;
this.weight = weight;
this.brithDate = brithDate;
}
public int getSno() {
return sno;
}
public void setSno(int sno) {
this.sno = sno;
}
public String getSname() {
return sname;
}
public void setSname(String sname) {
this.sname = sname;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public double getHight() {
return hight;
}
public void setHight(double hight) {
this.hight = hight;
}
public double getWeight() {
return weight;
}
public void setWeight(double weight) {
this.weight = weight;
}
public String getBrithDate() {
return brithDate;
}
public void setBrithDate(String brithDate) {
this.brithDate = brithDate;
}
public String toString() {
return "Student[" + sno + "," + sname + "," + sex + "," + hight + "," + weight + "," + brithDate + "]";
}
public String getBmi() {
double bmi = weight / (hight * hight);
String s = "";
if (bmi < 18.5)
s = "偏瘦";
else if (bmi >= 18.5 && bmi <= 23.9)
s = "时髦";
else if (bmi == 24)
s = "正常超重";
else if (bmi >= 24 && bmi <= 27.9)
s = "偏胖";
else if (bmi >= 28)
s = "肥胖";
return s;
}
想吐槽下,书本严重刊误,BMI公式:单位已经限制为,cm,和kg..根据他的算法.......
还有Date这个类的用法
算了我忍了.....