Q: Temperature array, potentially 2D? The assignment at hand is below:
Write a program that uses an array to store the temperature for five day objects.
Each object must encapsulate it's day name (ex: Monday, Tuesday...etc) and temperature
The controlling program will display the average temperature for that week.
Now I understand the basic principle of array's and how they are used, but the I am confused about two things:
public class TemperatureAndDay {
    public static void main(String[] args) {

    double [] temperature = new double [4];

    temperature[0] = 45.24;
    temperature[1] = 67.30;
    temperature[2] = 55.23;
    temperature[3] = 49.20;
    temperature[4] = 50.22;

    }
 }

Could anyone give me some tips/hints/examples of code that would give me a better understanding of what my professor wants me to do? Thank you.

A: According to the problem statement, I think you should create a Day class with data fields name (String) and temp (double). You could then store five such objects in an array to represent a week, and write a method that loops through this array to determine the average temperature.
public static double avgTemp(Day[] week) {
    double avg = 0;
    for (Day d : week) avg += d.temp();
    return avg / week.length;
}


A: *

*Write a class that holds a day and a temperature (make the attributes public or use getters and setters). 

*Make an array of 5 elements (not 4 like in your example) of that class. 

*Iterate over the array to calculate the average temperature.


A: *

*create a class called Day (or whatever).

*create attributes: double temperature, String dayName

*create a constructor: Day(String dayName, double temperature)

*in some other class, for example, name it TestProgram, create an array of Day objects:


Example:
Day[] days = new Day[4];
days[0] = new Day("Monday", 22.44);
...

Is it clear now?

A: I agree with @m0skit0 and want to add:
No, it is no 2 dimensional array needed as your headline states. You need an 1 dimensional array that holds the measurements like your sample code does.

A: 
Write a program that uses an array to store the temperature for five day objects.

I'm thinking that you need an array in main(), but nowhere else.

Each object must encapsulate it's day name (ex: Monday, Tuesday...etc) and temperature.  The controlling program will display the average temperature for that week.

So...what you need to do in a nutshell:


*

*Create objects of type TempDay or whatever you wish to call it (hopefully meaningful).

*Have fields in the object for the temperature of that day.  You can populate them any way you wish - through the constructor or mutators.

*Maintain these objects in an array in main() (most likely).

*The rest is just the raw mathematical definition of "average".



Could anyone give me some tips/hints/examples of code that would give
  me a better understanding of what my professor wants me to do? Thank
  you.

It's my hope that you walk away with more understanding from merely breaking the problem down than just receiving code.  Code can be written by anyone anywhere for any reason; the true mechanical process of solving the problem posed in the language requested is what you need to get.
EDIT:  The code you have currently also throws an ArrayIndexOutOfBoundsException when you try to put five elements in an array of size 4.
