Question

You are to write a banking application in c# that keeps track of bank accounts. It will consist of three classes, Account, Bank and BankTest. The Account class is used to represent a savings account i...

You are to write a banking application in c# that keeps track of bank accounts. It will consist of three classes, Account, Bank and BankTest.

The Account class is used to represent a savings account in a bank. The class must have the following instance variables:

  • a String called accountID                      
  • a String called accountName
  • a two-dimensional integer array called deposits (each row represents deposits made in a week). At this point it should not be given any initial value. Each row represents a week and each value in the row represents a deposit amount. Since the number of deposits can be different in each week, this will be a jagged array.
  • a double called balance, initially set to zero.

The class should have two overloaded constructors:

  • one takes parameters: accountID of type String and accountName of type String
  • the other takes parameters: accountID of type String, name of type String, and a two-dimensional integer array (this will be a jagged array).

Methods:

  • UpdateAccount: when called, simply goes through the deposits array and adds all the deposit amounts to the balance instance variable.
  • GetDeposits: When called this method will return a string representing the deposit amounts of the array.
  • ToString: returns a String which represents the ID, the name, the deposits, and the balance of a particular account as shown below. You must use the GetDeposit method in building the string. The output should look as shown below:

ID              : 2605

Name        :john doe

Deposits   : 90 50 70 | 40 50 |

Balance     : 300.00

The Bank class is used to keep track of the accounts of the bank. This class does not have a Main method as it is not the one that runs the application. The class must have one instance variable:

  • A one-dimensional array called accountsArray of type Account (the class Account is defined in the previous question). It will be able to take 10 accounts.

(Note: Feel free to create more instance variables, if there is a need.)

This class will have no constructors.

The class should have a method called AddAccount that takes a new account’s ID, name and a two-dimensional jagged integer array of deposits as parameters. Every time the AddAccount method is called with the appropriate values, it calls the Account constructor and assigns the newly created account to one of the elements of accountsArray. At each successful account addition, the method returns true, else it returns false.

The class should have a method called ApplyDeposits: goes through ONLY the populated elements of accountsArray and applies the deposit amounts (by calling the UpdateAccount method of the Account class).

The class should have a method called ToString. This method goes through the entire accountsArray and calls the ToString method of each element (each account). If the element is not populated, this method writes “No Account Found”. Remember, the ToString method returns a string.

The final class, BankTest, will create an object of the Bank class and add ten accounts by calling the AddAccount method on the bank object. After adding the accounts, the test class will call the ApplyDeposits method. Finally, the test class will call the ToString method of the Bank object.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Account.java


public class Account
{
/** Member variables of Account class */
/** a String called accountID */   
String accountID;

/** a String called accountName */
String accountName;
/** a two-dimensional integer array called deposits
* (each row represents deposits made in a week).
* At this point it should not be given any initial value.
* Each row represents a week
* and each value in the row represents a deposit amount.
* Since the number of deposits can be different in each week,
* this will be a jagged array */
int deposits[][];
/** a double called balance, initially set to zero. */
double balance;
  
  
/** Constructor with two parameters
* accountID of type String and accountName of type String
*/
public Account(String id, String name)
{
accountID = id;
accountName = name;
}
  
/** Constructor with three parameters
* accountID of type String and accountName of type String
* and a two-dimensional integer array
*/
public Account(String id, String name, int dep[][])
{
accountID = id;
accountName = name;
deposits = dep;
}
  
/** this method goes through the deposits array and adds all the deposit
* amounts to the balance instance variable.
*/
public void UpdateAccount()
{
/** deposits.length will give the number of rows in a two dimensional array */
/** deposits[i].length will give the number of columns in the ith row of the array */
for(int i=0; i<deposits.length; i++)
{
for(int j=0; j<deposits[i].length; j++)
{
balance = balance + deposits[i][j];
}
}
}
  
/** GetDeposits() method loops through the entire array and create a string with all
* the deposits value in the array
*/
public String GetDeposits()
{
String s="";
for(int i=0;i<deposits.length; i++)
{
for(int j=0; j<deposits[i].length; j++)
{
s = s + deposits[i][j] + " ";
}
s = s + " | ";
}
return s;
}
  
  
/** ToString() method creates a string that represents the complete account details
* It uses the GetDeposits() method to display the details of all the deposits
*/
public String ToString()
{
String s="";
s = s + "ID \t\t:" + accountID + "\n";
s = s + "Name \t\t:" + accountName + "\n";
s = s + "Deposits \t:" + GetDeposits() + "\n";
s = s + "Balance \t:" + balance + "\n\n";
return s;
}
}

public class Account * Member variables of Account class /** a String called accountID String accountID; /** a String calledpublic Account (String id, String name) accountID-id; accountName - name; * Constructor with three parameters accountID of ty/*x GetDeposits) method loops through the entire array and create a string with all * the deposits value in the array public

============================================================================================

Bank.java


public class Bank
{
/** A one-dimensional array called accountsArray of type Account.
* It will be able to take 10 accounts.
*/
Account accountsArray[] = new Account[10];
/** This static variable will hold the actual number of objects created
* and added to the accountsArray. It is initally -1 and gets
* incremented everytime a new account is created through AddAccount
* method
*/
public static int totalAccounts = -1;
  
/** AddAccount that takes a new account’s ID, name and a two-dimensional
* jagged integer array of deposits as parameters.
* Every time the AddAccount method is called with the appropriate values,
* it calls the Account constructor and assigns the newly created account
* to one of the elements of accountsArray. At each successful account addition,
* the method returns true, else it returns false.
*/
public boolean AddAccount(String id,String name, int dep[][])
{
Account ac = new Account(id,name,dep);
totalAccounts++;
accountsArray[totalAccounts]= ac;
return true;
}
  
/** ApplyDeposits: goes through ONLY the populated elements of accountsArray
* and applies the deposit amounts (by calling the UpdateAccount method of the Account class).
*/
public void ApplyDeposits()
{
for(int i=0; i<= totalAccounts; i++)
{
accountsArray[i].UpdateAccount();
}
}
  
/** ToString() method goes through the entire accountsArray
* and calls the ToString method of each element (each account).
* If the element is not populated, this method writes “No Account Found”.
* the ToString method returns a string.
*/
public String ToString()
{
String s="";
for(int i=0; i<10; i++)
{
if(accountsArray[i] == null)
s = s + "No Account Found \n";
else
s = s + accountsArray[i].ToString();
}
return s;
}
}

public class Bank A one-dimensional array called accountsArray of type Account * It will be able to take 10 accounts. Account* ApplyDeposits: goes through ONLY the populated elements of accountsArray * and applies the deposit amounts (by calling the

==============================================================================================

BankTest.java


/** Driver class */
/** This class will create an object of the Bank class and
* add ten accounts by calling the AddAccount method on the bank object.
* After adding the accounts, the test class will
* call the ApplyDeposits method. Finally, the test class
* will call the ToString method of the Bank object.
*/

public class BankTest
{
public static void main(String[] s)
{
Bank bank = new Bank();
boolean result;

int[][] deposits1 = {{50,34,45},{45,65,23,85,23},{88,56,34}};
int[][] deposits2 = {{45,89,23,45,23},{45,65,23,85,23},{88,56,34},{89,45,23}};
int[][] deposits3 = {{50,34,45},{45,65,23,85,23},{88,56,34},{45,65,23,85,23}};
int[][] deposits4 = {{50,34,45},{45,65,23,85,23},{88,56,34},{50,34,45}};
int[][] deposits5 = {{50,34,45},{85,23,88,34},{88,56,34},{66,43,67,23}};

result = bank.AddAccount("101","Joe",deposits1);
bank.AddAccount("102","Alice",deposits2);
bank.AddAccount("103","Nirmal",deposits3);
bank.AddAccount("104","Emman",deposits4);
bank.AddAccount("105","Joy",deposits5);

bank.ApplyDeposits();
System.out.println(bank.ToString());
  
}
}

* Driver class/ This class will create an object of the Bank class and * add ten accounts by calling the AddAccount method on

Output : ( I have created 5 Accounts to show "No Account Found" message in the output. Create 10 Accounts

as per the requirement in the BankTest class )

ID Name Deposits Balance :101 : Joe :50 34 45 45 65 23 85 23 88 56 34 I :548.0 ID Name Deposits Balance :102 :Alice :45 89 23

Add a comment
Know the answer?
Add Answer to:
You are to write a banking application in c# that keeps track of bank accounts. It will consist of three classes, Account, Bank and BankTest. The Account class is used to represent a savings account i...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please Write the following program in c# You are to write an application which will create...

    Please Write the following program in c# You are to write an application which will create a company, add agents (their name, ID, and weekly sales) to that company, and printout the details of all agents in the company. The application will contain three classes: Agent.cs, Company.cs, and CompanyTest.cs (this class is already provided). Flow of the application: The CompanyTest class creates an object of the Company class and reserves space for five agents. At this point if you call...

  • Look at the Account class below and write a main method in a different class to briefly experiment with some instances of the Account class.

    Look at the Account class below and write a main method in a different class to briefly experiment with some instances of the Account class.Using the Accountclass as a base class, write two derived classes called SavingsAccountand CurrentAccount.ASavingsAccountobject, in addition to the attributes of an Account object, should have an interest variable and a method which adds interest to the account. ACurrentAccount object, in addition to the instance variables of an Account object, should have an overdraft limit variable. Ensure...

  • Bank Accounts Look at the Account class Account.java and write a main method in a different...

    Bank Accounts Look at the Account class Account.java and write a main method in a different class to briefly experiment with some instances of the Account class. • Using the Account class as a base class, write two derived classes called SavingsAccount and CheckingAccount. A SavingsAccount object, in addition to the attributes of an Account object, should have an interest variable and a method which adds interest to the account. A CheckingAccount object, in addition to the attributes of an...

  • The current code I have is the following: package uml; public class uml {        public...

    The current code I have is the following: package uml; public class uml {        public static void main(String[] args) {              // TODO Auto-generated method stub        } } class Account { private String accountID; public Account(String accountID) { this.accountID = accountID; } public String getAccountID() { return accountID; } public void setAccountID(String accountID) { this.accountID = accountID; } @Override public String toString() { return "Account [accountID=" + accountID + "]"; } } class SuppliesAccount extends Account { private...

  • Java Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters...

    Java Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters long encryptedPassword : String key int Must be between 1 and 10(inclusive) accountId - A unique integer that identifies each account nextIDNum – a static int that starts at 1000 and is used to generate the accountID no other instance variables needed. Default constructor – set all instance variables to a default value. Parameterized constructor Takes in clearPassword, key. Calls encrypt method to create...

  • Please help JAVA Part II: Programming Module (80 marks): Write a banking program that simulates the operation of your l...

    Please help JAVA Part II: Programming Module (80 marks): Write a banking program that simulates the operation of your local bank. You should declare the following collection of classes: 1) An abstract class Customer: each customer has: firstName(String), lastName (String), age (integer), customerNumber (integer) - The Class customer has a class variable lastCustomerNumber that is initialized to 9999. It is used to initialize the customerNumber. Hence, the first customer number is set to 9999 and each time a new customer...

  • Exercise 1 Adjacency Matrix In this part, you will implement the data model to represent a graph. Implement the followi...

    Exercise 1 Adjacency Matrix In this part, you will implement the data model to represent a graph. Implement the following classes Node.java: This class represents a vertex in the graph. It has only a single instance variable of type int which is set in the constructor. Implement hashCode() and equals(..) methods which are both based on the number instance variable Node - int number +Node(int number); +int getNumberO; +int hashCode() +boolean equals(Object o) +String toString0) Edge.java: This class represents a...

  • c++ please    Define the class bankAccount to implement the basic properties of a bank account....

    c++ please    Define the class bankAccount to implement the basic properties of a bank account. An object of this class should store the following data: Account holder’s name (string), account number (int), account type (string, checking/saving), balance (double), and interest rate (double). (Store interest rate as a decimal number.) Add appropriate member func- tions to manipulate an object. Use a static member in the class to automatically assign account numbers. Also declare an array of 10 compo- nents of...

  • Design a bank account class named Account that has the following private member variables:

    Need help please!.. C++ programDesign a bank account class named Account that has the following private member variables: accountNumber of type int ownerName of type string balance of type double transactionHistory of type pointer to Transaction structure (structure is defined below) numberTransactions of type int totalNetDeposits of type static double.The totalNetDeposits is the cumulative sum of all deposits (at account creation and at deposits) minus the cumulative sum of all withdrawals. numberAccounts of type static intand the following public member...

  • Java Question 3 Implement a program to store the applicant's information for a visa office. You...

    Java Question 3 Implement a program to store the applicant's information for a visa office. You need to implement the following: A super class called Applicant, which has the following instance variables: A variable to store first name of type String. A variable to store last name of type String. A variable to store date of birth, should be implemented as another class to store day, month and year. A variable to store number of years working of type integer...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT