Results 1 to 3 of 3
  1. #1
    Neiladin is offline Member
    Join Date
    Nov 2010
    Posts
    3
    Rep Power
    0

    Default 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.

    Java 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);
        }
    
    }
    Last edited by Neiladin; 11-09-2010 at 08:08 PM. Reason: Edited to include code.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default

    two of the methods do not work correctly
    Pssst. Don't ever tell anyone which two.

    db

    -- How To Ask Questions The Smart Way

  3. #3
    Neiladin is offline Member
    Join Date
    Nov 2010
    Posts
    3
    Rep Power
    0

    Default

    I have resolved the problem, and I apologize, I mis-spoke about the methods. They work, I just called them at the wrong time. Thanks for the reply.

Similar Threads

  1. wierd NetBeans problem.
    By edi.gotieb in forum Forum Lobby
    Replies: 2
    Last Post: 10-09-2010, 01:31 PM
  2. Netbeans Problem
    By amitabh in forum NetBeans
    Replies: 9
    Last Post: 07-01-2010, 01:51 PM
  3. Problem with .jar working with netbeans
    By chipimdp in forum NetBeans
    Replies: 1
    Last Post: 05-14-2010, 09:25 AM
  4. Some Netbeans Problem
    By MuslimCoder in forum New To Java
    Replies: 0
    Last Post: 04-04-2010, 05:43 PM
  5. Netbeans 6.8 GUI design problem
    By newbiejava in forum NetBeans
    Replies: 0
    Last Post: 01-14-2010, 02:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •