我制作的程序旨在根据两个问题产生关于“穿着/着装”的文字建议。外面目前的温度和天气情况如何?基本Java程序:if语句?
将有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.");
}
}
此代码'如果((温度> = 33)&&(温度<= 60))'不可达...因为条件执行此代码为'如果(温度<= 32)' – 2013-03-13 05:00:45
您错过了'freezingSunny();'语句后面的'}'。不要在没有任何IDE的情况下编写Java代码。 – 2013-03-13 05:12:59