Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Remove the accounts class entirely and make all of the methods static and called

ID: 3532963 • Letter: R

Question



Remove the accounts class entirely and make all of the methods static and called from Main.  

1.      In Main:

1.      an array of 5 account numbers

2.      an array of 5 account balances (currency)

3.      an array of 5 account names (last name)

4.      call the static method that will fill the accounts array, passing the three arrays to the method to be filled

5.      a menu detailing entries to select search (a or A), average (b or B) or exit (x or X)

6.      accept an entry from the keyboard and use a while-loop to allow the user to make selections and to call the appropriate method based on the input until an x or an X is entered

7.      pass the already filled arrays and whatever other variables that are required by the method being called

8.      when an x or an X is entered terminate the while loop

2.      static methods called from Main:

1.      a separate static method to fill all three parallel arrays by keyboard inputs

2.      a separate static method to search the account number array and return a string output to main to be displayed using Console.WriteLine

1.      when found, the account number entered at the keyboard along with the corresponding balance and last name

2.      if nothing is found for the account number entered display

Explanation / Answer

// here is thecode that you want, just check whether it is fulfulling your requirenment



using System;


public class DriverProgram

{



public static void fillAccounts(int[] accountNumbers, double[] balance, string[] lastNames)

{






for (int i = 0; i < 5; i++)

{

Console.Write("Enter the integer account number "+(i+1)+": ");

accountNumbers[i] = Convert.ToInt32(Console.ReadLine());

Console.Write("Enter the account balance ");

balance[i] = Convert.ToDouble(Console.ReadLine());


Console.Write("Enter the account holder last name: ");

lastNames[i] = Console.ReadLine();


}

Console.WriteLine();


}


public static void searchAccounts(int[] accountNumbers, double[] balance, string[] lastNames, int account)

{


for (int i = 0; i < 5; i++)

{

if (accountNumbers[i] == account)

{

Console.WriteLine("Account # " + accountNumbers[i] + " has a balance of " + balance[i] + " for customer " + lastNames[i]);

return;

}

}


Console.WriteLine("account not found");

}

public static void averageAccounts(int[] accountNumbers, double[] balance, string[] lastNames)

{

double average = 0.0;

for (int i = 0; i < 5; i++)

{

average = average + balance[i];

}


Console.WriteLine("The average dollar amount for the accounts is: $" + average / 5);


}


public static void Main(string[] args)

{

int[] accountNumbers = new int[5];

double[] balance = new double[5];


string[] lastNames = new string[5];

char choice;


string ch;


try

{

DriverProgram.fillAccounts(accountNumbers,balance,lastNames);



do

{

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("*****************************************");

Console.Write("Enter an option->>");


ch = Console.ReadLine();


if (ch.Equals("a", StringComparison.CurrentCultureIgnoreCase))

{

Console.WriteLine("Enter an account number to search for: ");

int account = Convert.ToInt32(Console.ReadLine());


DriverProgram.searchAccounts(accountNumbers, balance, lastNames, account);


}

else if (ch.Equals("b", StringComparison.CurrentCultureIgnoreCase))

{

DriverProgram.averageAccounts(accountNumbers, balance, lastNames);


}

else

{

Console.WriteLine("you entered an incorrect option");


}

}while (!ch.Equals("x", StringComparison.CurrentCultureIgnoreCase));

}

catch (Exception)

{

Console.WriteLine("some error has occured either due to wrong input or some internal bugs");

}

}


}