I need to create a program that determines the season based off of a user-given
ID: 3652255 • Letter: I
Question
I need to create a program that determines the season based off of a user-given temperature. It has to be JOptionPane, and I think I've done it, but every time I try to run it it just gives a bunch of error messages.Does anyone see any blaring mistakes? I think it might have something to do with the "temperature" variable in the main method. It says it's not used, but I have to define it somehow, right?
import javax.swing.JOptionPane;
public class LabAssign6 {
public static void main(String args[]){
String repeat, inData;
for (int n = 1; n < 2;)
{
inData = JOptionPane.showInputDialog("Enter Temperature: ");
int temp = Integer.parseInt(inData);
repeat = JOptionPane.showInputDialog("Enter y or Y to run the program again: ");
if(repeat.equalsIgnoreCase("y"))
n=1;
else
n=2;
}
}
public static void findSeason (int temp){
{
if (temp >= 90)
JOptionPane.showMessageDialog(null, "It is probably Summer");
else if (temp >= 70 && temp < 90)
JOptionPane.showMessageDialog(null, "It is probably Spring");
else if (temp >= 50 && temp < 70)
JOptionPane.showMessageDialog(null, "It is probably Fall");
else if (temp >= -5 && temp < 50)
JOptionPane.showMessageDialog(null, "It is probably Winter.");
else
JOptionPane.showMessageDialog(null, "The temperature entered is outside the valid range.");
}
}
}
Explanation / Answer
Modified Program:
=====================================================
import javax.swing.JOptionPane;
public class LabAssign6 {
public static void main(String args[]){
String repeat, inData;
for (int n = 1; n < 2;)
{
inData = JOptionPane.showInputDialog("Enter Temperature: ");
int temp = Integer.parseInt(inData);
findSeason(temp);
repeat = JOptionPane.showInputDialog("Enter y or Y to run the program again: ");
if(repeat.equalsIgnoreCase("y"))
n=1;
else
n=2;
}
}
public static void findSeason (int temp){
{
if (temp >= 90)
JOptionPane.showMessageDialog(null, "It is probably Summer");
else if (temp >= 70 && temp < 90)
JOptionPane.showMessageDialog(null, "It is probably Spring");
else if (temp >= 50 && temp < 70)
JOptionPane.showMessageDialog(null, "It is probably Fall");
else if (temp >= -5 && temp < 50)
JOptionPane.showMessageDialog(null, "It is probably Winter.");
else
JOptionPane.showMessageDialog(null, "The temperature entered is outside the valid range.");
}
}
}
==========================================================
Sample output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.