Hello,
I have been struggling with this and it is due today. I have searched and read and am unable to determine what I am doing wrong. Thank you in advance.
class Accounts
{
// private class members
const int arrayLength = 5;
private int [] accountNumbArray = new int[arrayLength]; //create arrays
private double [] accountBalArray = new double[arrayLength];
private string [] accountNameArray = new string[arrayLength];
// fill all three parallel arrays with input
public static void fillAccounts(int[] accountNumbArray, double[] accountBalArray, string[] accountNameArray)
{
int arrayLength = 0;
for (int i = 0; i < accountNumbArray.Length; i++)
{
Console.Write("Enter integer account number ");
accountNumbArray[arrayLength] = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter account balance ");
accountBalArray[arrayLength] = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter account holder last name ");
accountNameArray[arrayLength] = Convert.ToString(Console.ReadLine());
} //end for
//search the account num array and display
// when found, account num entered and the corresponding bal and name
//if Not found, display "You entered an invalid account"
} //end fillAccounts method
public static void searchAccounts(int[] accountNumbArray, double[] accountBalArray, string[] accountNameArray)
{
int accountNum = 0;
bool found = false;
int x = 0;
Console.Write("Please enter the account number you wish to search for ");
accountNum = Convert.ToInt32(Console.ReadLine());
while (x < accountNumbArray.Length && accountNum != accountNumbArray[x])
{
++x;
double balance = accountBalArray[x];
string name = accountNameArray[x];
found = true;
Console.WriteLine("Account number " + accountNumbArray[x] + " has a balance of " + accountBalArray[x]
+ " and the account holder is " + accountNameArray[x]);
}
}
public static void averageAccounts(int[] accountNumbArray, double[] accountBalArray)
{
// compute and display average of all 5 bal as currency use length.
int balanceCount = 0;
double balance = accountBalArray[balanceCount];
double balanceSum = 0;
double averageBalance = 0;
for (int i = 0; i < accountNumbArray.Length; i++)
{
balanceSum = balanceSum + balanceCount;
}
averageBalance = (balanceSum/balanceCount);
} //end averageAccounts method
} //end public class accounts
class account_assignment //wrapper class for main
{
static void Main(int[] accountNumbArray, double[] accountBalArray, string[] accountNameArray)
{
char entry;
char a, A;
char b, B;
char x, X;
//instantiate one new Accounts object
Accounts accounts = new Accounts();
//call class methods to fill accounts Array
accounts.fillAccounts(accountNumbArray, accountBalArray, accountNameArray);
//menu detailing entnries to select search (a or A) average (b or B) exit (x or X)
Console.WriteLine("*****************************************");
Console.WriteLine("enter an a or A to search account numbers");
Console.WriteLine("enter a b or B to average the accounts");
Console.WriteLine("enter an x or X to exit program");
Console.WriteLine("*****************************************");
entry = Convert.ToChar(Console.ReadLine());
if (entry == 'a' || entry == 'A')
accounts.searchAccounts(accountNumb);
if (entry == 'b' || entry == 'B')
accounts.averageAccounts(accountNumbArray, accountBalArray);
if (entry == 'x' || entry == 'X')
Console.WriteLine("The program will now close");
//internal documentation
} //end main
} //end wrapper class for main
If I change this line to look like this:
if (entry == 'a' || entry == 'A')
accounts.searchAccounts(accountNumbArray, accountBalArray, accountNameArray);
Then I get this error:
Error 3 Member 'Assignment_3_Moon_AccountArrays.Accounts.searchAccounts(int[], double[], string[])' cannot be accessed with an instance reference; qualify it with a type name instead C:\Users\Teddi's Dell\AppData\Local\Temporary Projects\ConsoleApplication1\Program.cs 101 17 ConsoleApplication1
Error 2 Member 'Assignment_3_Moon_AccountArrays.Accounts.fillAccounts(int[], double[], string[])' cannot be accessed with an instance reference; qualify it with a type name instead C:\Users\Teddi's Dell\AppData\Local\Temporary Projects\ConsoleApplication1\Program.cs 88 13 ConsoleApplication1
Error 4 Member 'Assignment_3_Moon_AccountArrays.Accounts.averageAccounts(int[], double[])' cannot be accessed with an instance reference; qualify it with a type name instead C:\Users\Teddi's Dell\AppData\Local\Temporary Projects\ConsoleApplication1\Program.cs 103 17 ConsoleApplication1