Results 1 to 6 of 6

Thread: Array Problems

  1. #1
    ZedDriver is offline Member
    Join Date
    Nov 2012
    Posts
    4
    Rep Power
    0

    Default Array Problems

    Hello, I am trying to write a program that takes user input(in the form of temperatures in a week) and places it in an array, I want methods that return how many days (of the seven) were below freezing, how many days were above 100 degrees and what the largest change in temp between any two days are.

    The main problem I am having is understanding how to use methods with my array to do things, I was told I need to have them in separate files in the same folder so I have that but I can't figure out how to make them work together. Any help would be much appreciated!





    Array Problems-capture1.png


    Array Problems-capture2.png

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,785
    Rep Power
    7

    Default Re: Array Problems

    Lets clear things up a bit. In your main method you create and array of "temps" and then create a WeeklyTemps object passing the array as a parameter. Things look good so far if that is what is required. You then get the user to enter a single int. Two problems. How about a prompt so user knows what they are doing. What is the single int for? Are you supposed to ask the user for seven ints (the temps)? If so then what is the hard coded array at the start for? Next you create a BelowFreezing object but you do not have a BelowFreezing class. You do have a BelowFreezing method inside the WeeklyTemps class. Perhaps you should be calling that method instead. The last line is just wrong. You need to go back and review the textbook/class notes of how to call methods.

  3. #3
    ZedDriver is offline Member
    Join Date
    Nov 2012
    Posts
    4
    Rep Power
    0

    Default Re: Array Problems

    Thank you, yeah this code is a huge mess. I'm just going to restart from the beginning. Yeah I have no idea how to call methods from another class.

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,785
    Rep Power
    7

    Default Re: Array Problems

    It is really simple but many beginers make things harder for themselves. A simple example:
    Java Code:
    class Test {
        public static void main(String[] args) {
            Foo f = new Foo();
            f.doStuff(10);
        }
    }
    
    class Foo {
        public void doStuff(int val) {
            System.out.println(val);
        }
    }

  5. #5
    ZedDriver is offline Member
    Join Date
    Nov 2012
    Posts
    4
    Rep Power
    0

    Default Re: Array Problems

    Thank you. in your example, what does the "int val" represent. It's just a property right?

  6. #6
    ZedDriver is offline Member
    Join Date
    Nov 2012
    Posts
    4
    Rep Power
    0

    Default Re: Array Problems

    Never mind, I ran it and figured it out. Thanks again.

Similar Threads

  1. Problems inserting 1d array to 2d array grid
    By jumpgirl in forum New To Java
    Replies: 1
    Last Post: 03-26-2012, 03:04 AM
  2. array problems
    By Evan in forum New To Java
    Replies: 3
    Last Post: 05-05-2011, 10:05 PM
  3. Array problems!
    By Addez in forum New To Java
    Replies: 4
    Last Post: 08-29-2009, 06:56 PM
  4. Array problems..
    By smokeviolent in forum New To Java
    Replies: 1
    Last Post: 04-17-2009, 06:45 AM
  5. Array problems
    By Hosticus in forum New To Java
    Replies: 2
    Last Post: 01-18-2009, 02:48 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
  •