首页 > 解决方案 > 给定各种温度输入,如何确定归一化温度?

问题描述

我需要使用归一化的温度值来检查是否有人生病。

我编写了一个从摄氏温度转换为华氏温度的函数,但需要使用归一化温度编写相同的函数。

public void hasFever(int temperature1, int temperature2, int temperature3, int temperature4, String bodylocation) throws ArithmeticException, InputMismatchException {
    final int noOfTimesTempTaken = 4;
    if(bodylocation == "ear") { //Determine if someone has fever if temperature was taken by the ear
        final double feverTemperature = 98.6;   
        double temperature1InFahrenheit = (temperature1 * 9/5) + 32;
        double temperature2InFahrenheit = (temperature2 * 9/5) + 32;
        double temperature3InFahrenheit = (temperature3 * 9/5) + 32;
        double temperature4InFahrenheit = (temperature4 * 9/5) + 32;
        double avgTemp = (temperature1InFahrenheit + temperature2InFahrenheit + temperature3InFahrenheit + temperature4InFahrenheit) / noOfTimesTempTaken;
        if(avgTemp >= feverTemperature) {
            System.out.println("This person has a fever because their temperature of " + avgTemp + " is greater than normal which is 98.6");
        } else {
            System.out.println("This person does not have a fever because their temperature of " + avgTemp + " is less than normal which is 98.6");
        }
    }
}

标签: javanormalization

解决方案


首先,应该注意的是,归一化温度不是一个具有公认/标准含义的术语,适用于此。规范化一词有时用于表示“调整以处理测量不准确”,但这似乎不是您在这里尝试做的。

(必须说你还没有成功澄清你所说的normalize是什么意思,所以我们不得不猜测。这是我最好的猜测,基于你所说的。)

我想你正在寻找这样的东西:

double VALID_FAHRENHEIT_TEMP_THRESHOLD = 60.0;  // say

public double normalizeToFahrenheit(double temp) {
    if (temp >= VALID_FAHRENHEIT_TEMP_THRESHOLD) {
        return temp;
    } else {
        return temp * (9.0 / 5.0) + 32.0;
    }
}

但问题是这种“归一化”在科学和数学上都是不合理的。我们假设如果一个数字小于某个特定值,它必须以摄氏度而不是华氏度为单位。但这不一定是真的。摄氏和华氏刻度都下降到非常低的值。

更实际的是,如果有人淹死在冰冷的水中,他们的华氏温度可能会下降……可能接近冰点。它可能低于我们选择的阈值。如果我们假设它“必须”是摄氏度并转换它,我们会报告一个不正确的温度。

一个相关的问题是,一个奇怪的温度值可能是用户误读温度计、误听测量值或误输入值的结果;例如11.3,而不是101.3. 对错误的输入应用归一化会导致更多的误导性结果。


因此,鉴于这种“标准化”方法无效,您应该怎么做呢?

我的建议是让您的应用向用户报告异常情况。例如,向他们展示一个这样的对话框:

  The temperature xy degrees is outside of the expected range for human 
  temperatures in Fahrenheit.  

  Options: 

     1) Accept as a Fahrenheit value.  
     2) Apply Centigrade to Fahrenheit conversion. 
     3) Switch device to Centigrade mode.  
     4) Reenter value.

推荐阅读