Suliman Benhalim Suliman Benhalim - 1 year ago 103
Java Question

How To Make Declarations of an Array type Class

I am taking Data Structure Course, And I have a Question at the end of the Chapter that I couldn't solve.

class WeatherRecType {
int AvgHiTemp;
int AvgLoTemp;
float ActualRain;
float RecordRain;


Declare a one-dimensional array,
components, contains ten elements.


WeatherRecType WeatherListType[] = new WeatherRecType[10];


Assign the value 1.05 to the
field of the seventh record in

Answer: ???

How to assign the value to the
in the Array
field number 7?

I tried it like this, but it doesn't work:
Problem Image

The problem is solved, thanks to everyone who shared their knowledge with me.
Here is the correct answer:
Correct Answer Image

Answer Source

Seventh record of an array in most basic programming languages (C, Java etc.) translates to index 6, as the counting begins with the index 0. So you would require:

WeatherListType[6] = new WeatherRecType();
WeatherListType[6].ActualRain = 1.05f;

But since this is a Data Structure course you are referring to, 7 may work if you are talking in terms of Pseudo code or something.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download