JavaFX experiment -- identification of high risk population

During the epidemic, it is easy to add the difficulty of epidemic prevention to the flow of people. Please complete the code compilation of the simulated scanning temperature measurement interface according to the following information.
Design a mobile class named migrate, which includes the following:

① A String type private data field named name and the corresponding get/set method;
② A private data field of type int named areaFrom and the corresponding get/set method;
③ A private data field of double type named temperature and the corresponding get/set method;
④ One named critical_ The static double type constant of temperature, with a value of 37.3, indicates the critical body temperature;
⑤ A construction method with name, areaFrom and temperature as parameters;
⑥ An areaCheck(int areaFrom) method displays the status of a person's region according to the value of the person's region of origin (areaFrom), and returns one of "High Risk Area", "Normal Area" and "overseas area". The judgment basis is as follows:
area status={(High Risk Area, areaFrom=1@Oversea Area, areaFrom=2@Normal Area, areaFrom=3)┤
⑦ A String type temperatureCheck() method with temperature as the parameter, which displays the person's attention status by judging the person's temperature, and returns one of "High Temperature" and "Normal Temperature". The judgment basis is as follows:
Temperature status = {(high temperature, temperature ≥ critical temperature @ normal temperature, temperature < critical temperature) ⊿
⑧ A method named resultCheck() returns one of "Focus Group" and "Normal Group" according to the results of source area and body temperature test, and the judgment basis is as follows:
result={(Normal Group, Normal Area and Normal Temperature@Focus Group,other)┤
2) Design the following health information query form, and complete the coding, including the following content:

① The clear button can clear all information on the form;
② The query button can display the type of personnel (Focus Group "or" Normal Group ") according to the region and temperature of the personnel;
③ The scene size can be set to (350200);
④ You need to submit screenshots of the query results of the following three people.
name Zhangsan Lisi Wangwu
areaFrom 1 2 3
temperature 36.8 38.5 36.2
Tip: you can use the getText() method to get the information of the Text field. Use the Integer.parseInt(String) method and Double.parseDouble The (string) method converts the data to the desired types, respectively.

**

In fact, I have a problem with this code

**
Migrate class:

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("full name");
        grid.add(name, 0, 1);
        TextField nameT = new TextField();
        grid.add(nameT, 1, 1);
        Label area = new Label("region");
        grid.add(area, 0, 2);
        TextField areaT = new TextField();
        grid.add(areaT, 1, 2);
        Label tem = new Label("temperature");
        grid.add(tem, 0, 3);
        TextField temT = new TextField();
        grid.add(temT, 1, 3);
        Label result = new Label("result");
        grid.add(result, 0, 4);
        TextField resultT = new TextField();
        grid.add(resultT, 1, 4);
        Button empty = new Button("empty");
        Button inquire = new Button("query");
        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;
        }
        In this place, the conversion between int and double will throw an exception at run time. Although try and catch are used to eliminate the exception, there is a problem with the final result*/
        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("Health information query");
        primaryStage.setScene(new Scene(grid, 300, 275));
        primaryStage.show();
    }

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

Tags: Mobile

Posted on Tue, 09 Jun 2020 23:26:23 -0400 by Jak-S