JavaFX实验——疫情高危人群识别

疫情期间,人员流动很容易额外添加疫情防范的难度,请根据以下信息来完成模拟扫码测温界面的代码编写。
设计一个名为Migrant的流动人员类,包括下述内容:

①一个名为name的String类型私有数据域,以及对应的get/set方法;
②一个名为areaFrom的int类型私有数据域,以及对应的get/set方法;
③一个名为temperature的double类型私有数据域, 以及对应的get/set方法;
④一个名为CRITICAL_TEMPERATURE的静态double类型常量,值为37.3,表示临界体温;
⑤一个以name、areaFrom和temperature为参数的构造方法;
⑥一个areaCheck(int areaFrom)方法,根据人员的来源地区值(areaFrom)显示该人员所来自地区的状态,返回"High Risk Area"、“Normal Area”、“Oversea Area"中的一种,判断依据如下:
area status={(High Risk Area, areaFrom=1@Oversea Area, areaFrom=2@Normal Area, areaFrom=3)┤
⑦一个以temperature为参数的String类型temperatureCheck()方法,通过判断人员的体温值(temperature)显示该人员的关注状态,返回"High Temperature”、“Normal Temperature"中的一种,判断依据如下:
temperature status={(High Temperature, temperature≥临界体温 @Normal Temperature, temperature<临界体温)┤
⑧一个名为resultCheck()的方法,根据来源地区和体温检测的结果,返回"Focus Group”、"Normal Group"中的一种,判断依据如下:
result={(Normal Group, Normal Area and Normal Temperature@Focus Group,other)┤
2) 设计如下的健康信息查询窗体,并完成代码编写,包括下述内容:
JavaFX实验——疫情高危人群识别_第1张图片
①清空按钮可以清空表单上的所有信息;
②查询按钮可以根据人员所来自的地区和人员的体温,显示该人员所属的人员类型(“Focus Group"或"Normal Group”);
③场景可以设置大小为(350,200);
④需要提交下述三个人员的查询结果截图。
name Zhangsan Lisi Wangwu
areaFrom 1 2 3
temperature 36.8 38.5 36.2
提示:可以使用getText()方法获取Text域的信息,使用Integer.parseInt(String)方法和Double.parseDouble(String)方法将数据分别转换为所需要的类型。

**

事实上,我这个代码是有问题的…

**
Migrant类:

package sample;

public class Migrant {
    private String name;
    private int areaFrom;
    private double temperature;
    static double CRITICAL_TEMPERATURE = 37.3;
    public Migrant(String name, int areaFrom, double temperature){
        this.name = name;
        this.areaFrom = areaFrom;
        this.temperature = temperature;
    }
    public String getName(){
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAreaFrom() {
        return areaFrom;
    }
    public void setAreaFrom(int areaFrom) {
        this.areaFrom = areaFrom;
    }
    public double getTemperature() {
        return temperature;
    }
    public void setTemperature(double temperature) {
        this.temperature = temperature;
    }
    public String areaCheck(int areaFrom){
        if(areaFrom == 1)
            return "High Risk Area";
        else if(areaFrom == 2)
            return "Oversea Area";
        else if(areaFrom == 3)
            return "Normal Area";
        return null;
    }
    public String temperatureCheck(double temperature) {
        if (temperature < CRITICAL_TEMPERATURE)
            return "Normal Temperature";
        else
            return "High Temperature";
    }
    public String resultCheck(){
        if(areaFrom ==3 && temperature < CRITICAL_TEMPERATURE)
            return "Normal Group";
        else
            return "Focus Group";
    }
}

Main:

package sample;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        GridPane grid = new GridPane();
        grid.setAlignment(Pos.CENTER);
        grid.setHgap(5);
        grid.setVgap(5);
        grid.setPadding(new Insets(5, 5, 5, 5));
        Label name = new Label("姓名");
        grid.add(name, 0, 1);
        TextField nameT = new TextField();
        grid.add(nameT, 1, 1);
        Label area = new Label("地区");
        grid.add(area, 0, 2);
        TextField areaT = new TextField();
        grid.add(areaT, 1, 2);
        Label tem = new Label("体温");
        grid.add(tem, 0, 3);
        TextField temT = new TextField();
        grid.add(temT, 1, 3);
        Label result = new Label("结果");
        grid.add(result, 0, 4);
        TextField resultT = new TextField();
        grid.add(resultT, 1, 4);
        Button empty = new Button("清空");
        Button inquire = new Button("查询");
        HBox hBox = new HBox(5);
        hBox.setAlignment(Pos.BOTTOM_RIGHT);
        hBox.getChildren().addAll(empty, inquire);
        grid.add(hBox, 1, 5);
        String n = nameT.getText();
        int a = Integer.parseInt(areaT.getText());
        double t = Double.parseDouble(temT.getText());
        /*int a;
        try{
            a = Integer.parseInt(areaT.getText());
        }catch (NumberFormatException e){
            a = (int)3;
        }
        double t;
        try{
            t = Double.parseDouble(temT.getText());
        }catch (NumberFormatException b){
            t = (double)0;
        }
        这个地方,int跟double的转换在运行时会抛出异常,虽然使用try、catch消除了异常,但是最终运行出来的结果是有问题的*/
        Migrant m = new Migrant(n, a, t);
        empty.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent actionEvent) {
                nameT.setText("");
                areaT.setText("");
                temT.setText("");
                resultT.setText("");
            }
        });
        inquire.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent actionEvent) {
                resultT.setText(m.resultCheck());
            }
        });
        primaryStage.setTitle("健康信息查询");
        primaryStage.setScene(new Scene(grid, 300, 275));
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

你可能感兴趣的:(JavaFX实验——疫情高危人群识别)