私が作成したプログラムは、2つの質問に応じて、「着る/着る」ものに関する推奨事項をテキストで生成するように設計されています。外の現在の気温と気象条件は何ですか。
3つの範囲があります:(<= 32)(33-55)(56+)度Fそして気象条件の4つの選択:晴れ、曇り、雨、雪
以下のコードを使用すると、32 F未満の温度を入力した場合にのみ、適切な推奨を生成できます。残りの2つの温度範囲に対して同じコードを実行した場合、凍結一時変数入力と同じように推奨を生成するにはどうすればよいですか?
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.");
}
}