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

• 12-04-2012, 05:07 PM
Irish Rayray
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.

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.
• 12-04-2012, 05:26 PM
StormyWaters
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.
• 12-04-2012, 05:26 PM
Tolls
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?
• 12-04-2012, 05:31 PM
Irish Rayray
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.