我制作的程序旨在根据两个问题在文本中生成关于“穿/着装”的建议。目前外面的温度和天气情况如何。
将有 3 个范围:(<=32)(33 - 55) (56+) 华氏度和 4 个天气条件选择:晴天、多云、下雨、下雪
使用下面的代码,我只能在输入低于 32 F 的温度时生成适当的建议。如果我对其余两个温度范围执行相同的代码,我将如何生成建议,就像冻结温度变量输入一样?
if (temperature <= 32){
if (weatherCondition == 4){
freezingSnowing();
}
else if (weatherCondition == 3){
freezingCloudy();
}
else if (weatherCondition == 2){
freezingRain();
}
else {
freezingSunny();
}
if ((temperature >= 33) && (temperature <= 60)){
if (weatherCondition == 4){
warmSnowing();
}
else if (weatherCondition == 3){
warmCloudy();
}
else if (weatherCondition == 2){
warmRain();
}
else {
warmSunny();
}
}
}
//These are the recommendations that I would like to appear//
public static void freezingSnowing()
{
JOptionPane.showMessageDialog(null, "It's is snowing! I recommend that you dress very warm" +
"and wear a large coat that is preferably water proof.");
}
// Temp <= 32 and weather condition = 3 //
public static void freezingCloudy()
{
JOptionPane.showMessageDialog(null, "Yikes it's below freezing, but at least it's just cloudy." +
" I would suggest that today you dress very warm and bring rain or snow gear just in case.");
}
// Temp <= 32 and weather condition = 2 //
public static void freezingRain()
{
JOptionPane.showMessageDialog(null, "Be careful freezing temperatures and rain is very dangerous!" +
" If however you will be venturing outside remeber to dress warm and be cautious of icy spots.");
}
// Temp <= 32 and weather condition = 1 //
public static void freezingSunny()
{
JOptionPane.showMessageDialog(null, "Looks may be decieving today. Don't forget to dress warm" +
" it looks nice and sunny out but it is still freezing.");
}
public static void warmSnowing()
{
JOptionPane.showMessageDialog(null, "It's is snowing, but based on the temperature it could turn to rain any minute! I recommend that you dress very warm" +
"and wear a large coat that is preferably water proof.");
}
}