这次我们结合我上两篇关于简易计算器界面设计和通过BMI判断人的体型的文章来写一个“体型计算器”(我们初学者要学会综合的、系统的、规范的利用所学知识,完成需求)。同样,相关步骤给出注释以方便大家交流学习。
代码:
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
abstract class People{
int weight;
int height;
public People(int weight, int height) {
this.weight = weight;
this.height = height;
}
abstract public float stature();
public String drawResult() {
System.out.println("体重:"+this.weight+"(KG) 身高:"+this.height+"(cm)");
String drawresult = new String();
float statureResult = this.weight/this.stature()-1;
if(statureResult>=-0.1&&statureResult<=0.1) {
drawresult = "标准";
}else if (statureResult<-0.1) {
dr