Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Using your IDE, define class BankAccount, with its 2 subclasses, Savings Account & Checking Account [25 pts] A. BankAccount class Instance Variable account Num
Using your IDE, define class BankAccount, with its 2 subclasses, Savings Account & Checking Account [25 pts] A. BankAccount class Instance Variable account Num createDate balance type Class Variable (static) bankName currentNumber Variable Type String String int String Variable Type String int Modifier public public public private B. Define the following methods for this class default private Note: The currentNumber is a static variable that should be initialized to 0. This value will be updated by incrementing its current value by 1 each time a new BankAccount object is created, and assigned to accountNum instance variable The incremented value should be assigned to the account Num variable of any new BankAccount instance that gets created by the constructor 2-arg constructor that uses accountNum, createDate (current date) 4-arg constructor that uses all four instance variables all getter and setter methods other supporting methods, as you deem appropriate C. Define main() method for this class that will: First print 'Welcome Message' Ask user which account and with what balance does it want to create Use Scanner to read user input Create 2 accounts Print account details - - 2. For this Section of the lab, you will use the MyArrayBag class you created in Assignment-1. Since a Bag can in principle hold any type of object that the programmer chooses, or as mandated by the application requirements, for this Section the bag object you created should hold BankAccount objects. [30 pts] (a) Before you begin testing the MyArrayBag class with BankAccount objects, write a method named 'equals(aBankAccountObj)' method. As the method signature indicates, the argument aBankAccountObj' will be bankaccount object you will be validating equality with. This method should return a boolean, to indicate whether or not the two objects are equal Hint: You will need to write the compareTo(aBankAccountObj) method, as discussed in class Your equals(aBankAccountObj) method can then be used in turn to call the compareTo(aBankAccountObj) method and then finally return a boolean based on what compare To method returned The logic to compare two bankaccount objects and determine whether or not they are equal is left to your discretion and will be acceptable (b) Create an adapter BankAccountTester that will use the MyArrayBag class to create a bag object and manipulate it using BankAccount objects: i. Create a mix of CheckingAccount and Savings Account objects and add to the bag. You must have at least 4 BankAccount objects in the bag Print bag contents Hint: You will need to define print method to print data of bank accounts to console iii. Remove account(s), using both remove methods (random and a specified account) as defined in the interface ii. iv. Print bag size before and after account(s) removal(s) v. Pick an arbitrary amount to print all accounts with balance greater than the amount vi. Since a Bag can have duplicate items, be sure to have at least one duplicate account object in your bag 3. In this section you will implement an ADT Bag using Linked Data. For that, create a class named MyLinkedBag that should also implement the same BagInterface that was implemented by your MyArrayBag class in Assignment-1. As a result, your MyLinkedBag class will have to implement all methods defined in the interface. [30 points] This class should: (a) Have a private instance variable called 'num Nodes', whose initial value should be 0. This variable will store an integer value, which will represent the count of node elements in the bag at any point in time (b) Have a default instance variable called 'firstNode' that will store a node object, which will be implemented through an inner class called 'Node', as outlined below. This variable will represent the starting node that can then be used to traverse through all other nodes in the bag (c) Have a no-arg constructor (d) Have the following methods: add(aBankAccount) i. This method should add a bankaccount object and return true to indicate if add was successful and false otherwise This method should take a bankaccount object as an argument This method will create a new Node object and set its data attribute to the bankaccount object object and set the next attribute of the new node to be what was previously firstNode and the firstNode attribute to this newly created node Note: - - The add method should handle both conditions, of adding a node to an empty bag, and also the case if the bag had node(s) prior to this addition ii. contains(aBankAccount) - This method should check to see if aBankAccount object exists in the bag The method should return true if the object exists and false otherwise Note: Keep in mind since the bankAccount object is stored as data within the linked node, you will need to traverse through the nodes and compare each node's data object to object coming in as argument to find the match 7 iii. remove() This method should delete the first node of the bag This method should return true if successful and false otherwise Note: Once the deletion is completed, the firstNode attribute should point to what was previously the node next to first node iv. remove(aBankAccount) This method deletes aBankAccount object in the bag This method should return true if successful and false otherwise Note: As in the case of contains method above, you will need to traverse through the nodes and compare each node's data to find the match As in the case of contains method above, you will need a way to compare two aBankAccount objects objects to check equality v. toArray() - - The method should return an array all aBankAccount objects in the bag Keep in mind that since bank account objects are stored as data within the linked nodes of the bag, you will need to traverse through the nodes within the bag and build the array of aBankAccount objects as retrieved from each node 4. Since you are creating MyLinkedBag class, you will not be using an array anymore to store objects. Instead, you will be creating a Node class, as inner class within your MyLinkedBag class, to facilitate storage and retrieval of stored objects [20 points] This Node inner class should: (a) Have an instance variable called 'data', that will store objects of type BankAccount (b) Have an instance variable called 'next', that will store a Node object, which represents the node next to current node (c) Have a no-arg constructor (d) Have a 1-arg constructor, that takes an object as an argument (e) Have a 2-arg constructor, that takes an object and Node object as two arguments. This constructor should set the object to the data attribute and Node object to the next node attribute of the current node, as discussed in class (f) Have getters and setters for each of the 2 instance variables for the class 5. Define an adapter class, BuildBag, for testing, whose main() method will contain the code to perform testing. The method should do the following [20 points] Along the lines of testing with bankaccount objects for the array-based bag, do the following to test your Linked Bag (a) Create 2 CheckingAccount and 2 SavingsAccount objects, with appropriate data. The data required to create the bank accounts can be hard-coded in the main() method (b) Instantiate your LinkedBag class, using the appropriate constructor(s) (c) Add the 4 bank account objects created above to the LinkedBag object using the add() method (d) Remove a bank account object from the bag (e) Print bag contents with details for each BankAccount in the bag
Step by Step Solution
★★★★★
3.40 Rating (147 Votes )
There are 3 Steps involved in it
Step: 1
Below is the implementation of the BankAccount class and its subclasses SavingsAccount and CheckingAccount along with the MyLinkedBag class and an adapter class BuildBag for testing Please note that t...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started