# Array Problems

• 11-01-2012, 09:04 PM
ZedDriver
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!

Attachment 4193

Attachment 4194
• 11-02-2012, 12:08 AM
Junky
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.
• 11-02-2012, 12:35 AM
ZedDriver
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.
• 11-02-2012, 12:39 AM
Junky
Re: Array Problems
It is really simple but many beginers make things harder for themselves. A simple example:
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);     } }```
• 11-02-2012, 11:44 PM
ZedDriver
Re: Array Problems
Thank you. in your example, what does the "int val" represent. It's just a property right?
• 11-02-2012, 11:46 PM
ZedDriver
Re: Array Problems
Never mind, I ran it and figured it out. Thanks again.