C# (1) Create a C# class for a bank account object with the following 3 properti
ID: 3826290 • Letter: C
Question
C#
(1) Create a C# class for a bank account object with the following 3 properties: account number (int type), customer name(string type), and account balance(double type).
(2) Define an array type as the bank account class to store the 10 bank accounts. Use a "for loop" to generate 10 bank accounts accordingly to the following specification: (a) Each account number is 7 digits with 5 digits random number (from 10000 to 99999) plus 2 check digits. The check digits are the sum of the five digits added together. (b) Use a List to initialize 10 customer names of your choice and randomly assign a name to each account customer name without duplication. (c) Randomly create and assign a balance amount to the account balance property ranging from $100.00 to $5,999.99. (d) Print the 10 account information during your creation of them, one line per account.
(3) Use one of the selection sort, bubble sort, or insertion sort to sort the array of 10 bank account objects into descending order of account balance.
(4) Print the 10 account information after they are sorted in descending order of account balance, one line per account. Compute and print the average account balance amount for the 10 accounts.
Explanation / Answer
---------------------------Program To create Account Name, Account number, and Account Balance-------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
namespace BankAccount
{
class Account
{
int accountNumber;
String customerName;
double accountBalance;
static int count = 0;
static int[] accountNumberArray = new int[10];
public Account(int acNumber, ArrayList custName, double acBalance)
{
accountNumber = accountNumberArray[count];
customerName = custName[count].ToString();
accountBalance = acBalance;
Console.WriteLine("Account Number: "+accountNumber+" Customer Name: " +customerName+ " Account Balance: "+accountBalance);
count++;
}
public static int accountNum(int acNumber) //this function generate the account number according to 2 digit = addition of 5 digit
{
String accountNum = acNumber.ToString();
if(accountNum.Length < 7)
{
Console.Write("Enther exact 7 digit account number:");
return 0;
}else if(accountNum.Length > 7)
{
Console.Write("Enther exact 7 digit account number:");
return 0;
}
String str = "";
String str2 = "";
for(int i = 0; i < accountNum.Length; i++)
{
if (i < 2)
{
str = str + accountNum[i];
//Console.WriteLine(str);
}else
{
str2 = str2 + accountNum[i];
}
}
int twoDigit = int.Parse(str);
int fiveDigit = int.Parse(str2);
int fiveDigit2 = 0;
for(int i=0; i<str2.Length; i++)
{
String str3 = str2[i].ToString();
fiveDigit2 = fiveDigit2 + int.Parse(str3);
//Console.WriteLine(fiveDigit2);
}
twoDigit = fiveDigit2;
str = twoDigit.ToString();
str2 = str + str2;
int exactAccountNumber = int.Parse(str2);
//Console.WriteLine(exactAccountNumber);
return exactAccountNumber;
}
public static void bubbleSort()
{
int n = accountNumberArray.Length;
for (int i = 0; i < n - 1; i++)
for (int j = 0; j < n - i - 1; j++)
if (accountNumberArray[j] > accountNumberArray[j + 1])
{
// swap temp and arr[i]
int temp = accountNumberArray[j];
accountNumberArray[j] = accountNumberArray[j + 1];
accountNumberArray[j + 1] = temp;
}
}
static void Main(string[] args)
{
int accountNumberPattern = 1113477;
for (int i = 0; i < accountNumberArray.Length; i++)
{
accountNumberPattern = accountNumberPattern + i;
accountNumberArray[i] = Account.accountNum(accountNumberPattern);
}
Account.bubbleSort();//To sort the array of account number
ArrayList arrayList = new ArrayList();
arrayList.Add("Vijay");
arrayList.Add("Jay");
arrayList.Add("rahul");
arrayList.Add("ajay");
arrayList.Add("narendra");
arrayList.Add("kishan");
arrayList.Add("vinay");
arrayList.Add("sajjan");
arrayList.Add("holi");
arrayList.Add("devil");
Account ac = new Account(1113477, arrayList, 2993);
Account ac1 = new Account(1113478, arrayList, 2993);
Account ac2 = new Account(1113467, arrayList, 2993);
Account ac3 = new Account(1113577, arrayList, 2993);
Account ac4 = new Account(1113407, arrayList, 2993);
Account ac5 = new Account(1113427, arrayList, 2993);
Account ac6 = new Account(1113497, arrayList, 2993);
Account ac7 = new Account(1143477, arrayList, 2993);
Account ac8 = new Account(1123477, arrayList, 2993);
Account ac9 = new Account(1153477, arrayList, 2993);
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.