# Thread: Calculating Which Members in a java program have a gold Membership

1. Member
Join Date
Apr 2012
Posts
21
Rep Power
0

## Calculating Which Members in a java program have a gold Membership

Hi all,

I am doing some basic java programs and have run into a slight problem at the moment and was wondering if anybody can help.

Java Code:
```public class Main{
public static void main(String args[])
{
Member[] Mem = new Member[5];

Mem[0] = new Member(78478, "Alice Martin", true, 3400);
Mem[1] = new Member(42535, "Bernard Nolan", false, 2500);
Mem[2] = new Member(65464, "Claire Owens", true, 3500);
Mem[3] = new Member(67478, "Dave Pearson", true, 3300);
Mem[4] = new Member(76964, "Edel Quirke", false, 2200);

int TotalMembers = 0;
double averageFee = 0;

for(int i = 0; i < Mem.length; i++)
{
if (Mem[i] != null)
{
TotalMembers ++;
}
averageFee += Mem[i].getFee() ;
}
averageFee = averageFee/5;

System.out.println("Total Number of Members is " + TotalMembers);
System.out.println("Total Number of Members with Gold Rating is ");
System.out.println("Average Fee for Members with Gold Rating is ");
System.out.println("Average Fee payed is " + averageFee);
System.out.println("-----------------------------------------------------------------");

System.out.println("Alice's new Mebership fee is " + (Mem[0].getFee() + 100));
System.out.println("Bernard's new Mebership fee is " + (Mem[1].getFee() + 100));
System.out.println("Claire's new Mebership fee is " + (Mem[2].getFee() + 100));
System.out.println("Dave's new Mebership fee is " + (Mem[3].getFee() + 100));
System.out.println("Edel's new Mebership fee is " + (Mem[4].getFee() + 100));

Mem[4].setName("Edel Reynolds");
System.out.println("Edel Quirke's name has changed to " + Mem[4].getName());

}
}```
What I'm trying to do is find out the total number of members with gold rating then get the average fee for them.
I know that i can do the average fee bit but im having trouble geting the total number of gold members bit.

Any help will be appreciated.
Last edited by Irish Rayray; 12-04-2012 at 05:46 PM.

2. Senior Member
Join Date
Feb 2009
Posts
312
Rep Power
13

## Re: Calculating Which Members in a java program have a gold Membership

What have you tried? If you can get the average fee, then you should already have the number of gold members.

3. Moderator
Join Date
Apr 2009
Posts
13,541
Rep Power
28

## Re: Calculating Which Members in a java program have a gold Membership

OK, pretend you have a stack of cards rather than that array.
Those cards hold the Member data above.

How would you do this by hand?

4. Member
Join Date
Apr 2012
Posts
21
Rep Power
0

## Re: Calculating Which Members in a java program have a gold Membership

I dont have the average Fee done for gold Members but i do have it done for overall fee along with a few other little things but i didn't include them as they have nothing to do with this if you wish ill edit it to include them.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•