Not sure if this is actually a NetBEans problem...
Hello all,
I am taking a beginning programming course at a university in Oklahoma and we are using Java as the beginning language. I love it. We have done several small assignments so far, using Net Beans as our recommended IDE, and so far it has been working well.
We are on the eleventh assignment and I have run into a problem. I am unsure of whether this is a problem with Net Beans or a problem with using different machines to program and display.
I have written a program in Net Beans using the school's lab computers. It has three or four different methods that are being called at different places in the main method, and on the school machines it runs perfectly, and all the information I want to be shown is shown correctly. However, when I try to paste the code from an email I sent to myself at home, two of the methods do not work correctly. It is not a copy/paste error, and all of the code is exactly the same. Is this a user error (I have pretty much ruled that out) or is this some kind of definition error or software/hardware error? Thank you in advance for any help.
Neiladin
Edited to include code.
Code:
package javaapplication1;
import javax.swing.JOptionPane;
public class Main {
public static void main(String[] args) {
String cityNameA = "City A";
String cityNameB = "City B";
double [] cityA = new double [5];
double [] cityB = new double [5];
JOptionPane.showMessageDialog(null, "First enter the high temperatures for City A.");
cityA = getTemps(cityA);
JOptionPane.showMessageDialog(null, "Now enter the high temperatures for City B.");
cityB = getTemps(cityB);
double averageA = averageTemp(cityA);
double averageB = averageTemp(cityB);
int warmerA = numberWarmer(cityA, cityB);
int warmerB = numberWarmer(cityB, cityA);
displayResults(cityNameA, cityA, averageA, warmerA);
displayResults(cityNameB, cityB, averageB, warmerB);
}
public static double [] getTemps(double [] city) {
for (int n = 0; n < 5; n++){
city[n] = Double.parseDouble(JOptionPane.showInputDialog(null,
"Temperature for day " + (n + 1)));
}
return city;
}
public static double averageTemp(double [] temps) {
double total = 0;
double average;
for (int n = 0; n < temps.length; n ++) {
total += temps[n];
}
average = total / temps.length;
return average;
}
public static int numberWarmer(double [] cityOne, double [] cityTwo) {
int warmer = 0, result;
for (int n = 0; n < cityOne.length; n++) {
if (cityOne[n] > cityTwo[n])
warmer ++;
}
result = warmer;
return result;
}
public static void displayResults(String cityName,
double [] temps, double average, int warmer) {
String theResults = "";
theResults += cityName + "\n";
for (int n = 0; n < temps.length; n ++) {
theResults += "Day " + (n + 1) + " " + temps[n] + "°" + "\n";
}
theResults += "The average high temperature is: " + average + "°" + "\n" +
"City A was warmer " + warmer + " days.";
JOptionPane.showMessageDialog(null, theResults);
}
}