473,385 Members | 1,372 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Quick question about Arrays

Hi, say i have a class and I create an array within the constructor in the class, and then i have a method and i want to add to the array in that method, how would I go about doing that? (my array is an array of Grade objects in a Grade support class i have made)

here is what i have been trying:
Expand|Select|Wrap|Line Numbers
  1. public class GradeList {
  2.  
  3.    public  GradeList(int n) {
  4.       Grade[] grades= new Grade[n];
  5.    }
  6.  
  7.    public void add(double max, double weight){
  8.       int i=0;
  9.       grades[i]=new Grade(max, weight);
  10.       //i get an error saying that variable grades cannot be found
  11.       i++;
  12.     }
  13. }
Any help that would allow me to do what im trying to accomplish would be appreciated, thank you!
Oct 28 '07 #1
1 1011
Ganon11
3,652 Expert 2GB
That's because grades is declared (and thus destroyed) within your constructor. It no longer exists when you get to add. Make grades a private data member, declared outside the constructor and any methods. Then take out the Grade keyword in front of grades in your constructor, and you should be fine.
Oct 29 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: windandwaves | last post by:
is there a quick way to compare the results from two arrays and note the differences? I have two identical tables in MySql (backup and current table) and I want to work out the differences between...
12
by: Eva | last post by:
Hi, I try to implement quick sort. I sort vectors by their first value. 10 2 3 4 9 3 5 6 10 4 5 6 must be 9 3 5 6 10 2 3 4 10 4 5 6 The prog works great on maybe 500 vectors, but I have an...
8
by: Jm | last post by:
Hi All Ive asked this question in ms.public.dotnet.framework.interop but havent got a reply so im hoping someone may be able to help here. I am a bit of a newbie to vbnet and am having trouble...
3
by: Mike Cain | last post by:
I have an odd situation I'm trying to understand..... I'm using MS VS 7.0 C++ with the MFC CBuffer class. If I do this: #define NUM_ELEMENTS 2 CBuffer<char, 512 x; CBuffer<char, 512 ...
13
by: ralphedge | last post by:
These sorts work fine on 100000 ints but if I go much higher they will both segmentation fault **************************MERGESORT********************* mergesort(int *a, int size) //a is...
0
by: bharathreddy | last post by:
Delegates Here in this article I will explain about delegates in brief. Some important points about delegates. This article is meant to only those who already know delegates, it will be a quick...
6
by: SuperDuper | last post by:
Just a few quick questions. 1) How would I count the length of words in 5 certain strings. SomeString.s1, SomeString.s2, etc.. 2) How to compute the average word length? 3) How to compute...
0
by: r035198x | last post by:
Inheritance We have already covered one important concept of object-oriented programming, namely encapsulation, in the previous article. These articles are not articles on object oriented...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.