【发布时间】:2019-12-12 01:36:25
【问题描述】:
我需要使用归一化的温度值来检查某人是否有病。
我编写了一个从摄氏温度转换为华氏温度的函数,但需要使用归一化温度编写相同的函数。
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");
}
}
}
【问题讨论】:
-
我会很好,如果你能告诉我们你的问题到底是什么。你得到什么输出?预期的输出是什么?
-
您没有任何代码,可能会抛出
ArithmeticException或InputMismatchException,因此您可以删除throws ArithmeticException, InputMismatchException。ArithmeticException也是 unchecked exception,因此不必在方法签名中。 -
我的问题在于如何将我的温度变量“转换”为标准化温度,该温度可以根据 hotTemperature 进行评估以确定该人是否生病。
-
可能只有我一个人,但我不知道你所说的“标准化”是什么意思。你能向我解释一下在这种情况下这意味着什么吗?
-
因为在根据发烧温度评估值之前,可以用摄氏或华氏(我将摄氏转换为华氏的原因)来测量温度。我想重构该函数,以便能够比较温度值(无需从一个单位转换为另一个单位),以确定该人是否生病。
标签: java normalization