Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Objective In this assignment, you will practice solving a problem using object-oriented programming and specifically you will use the concept of object composition i.e., has

image text in transcribedimage text in transcribedimage text in transcribed

Objective In this assignment, you will practice solving a problem using object-oriented programming and specifically you will use the concept of object composition i.e., has a relationship between objects). You will implement a Java application, called BankingApplication that could be used in a bank. You are asked to implement three classes: Transaction, Statement, and Statement Driver. Each of these classes is described below. Problem Description Transaction class The Transaction class represents a deposit or withdrawal. The transaction has four instance variables: description of type String), amount of type double), date (of type String), and action (of type int). The possible actions are WITHDRAWAL (0), DEPOSIT (1) and INTEREST (2). Implement the following methods for the Transaction class: A constructor to initialize all instance variables. A value for each instance variable will be passed as a parameter to the constructor. The parameters must be in the order description, amount, date, and action. Getters for all instance variables. Setter methods for each instance variable. e quals: a method to test the equality of two items. Two items are considered to be equal if they have the same description and the same date. The comparison must be case insensitive. toString: a method that returns a nicely formatted string description of the item. All items should be separated by tabs (use "\t") and the entire Transaction should be displayed on one line. Use the Number Format or DecimalFormat class to display amounts with exactly two digits following the decimal place. Declare WITHDRAWAL and DEPOSIT as named constants and use the constants throughout your program (see p. 13). Statment class: The Statement class represents a collection of transactions. The Statement class is identified by the following instance variables: account: a string that represents the account holder's name. trans: an instance variable of type array of Transaction with size of 5 numTrans: an instance variable that indicates the number of transactions that have been added to the statement Implement the following methods for the Statement class: A constructor that takes as input the account holder's name and the account's initial balance. The constructor creates a statement by recording the customer's name, setting the balance instance variable (type double) to the initial value and instantiating the array of transactions. Each item in the array will initially be null by default. Set numTrans to 0. addtrans(): a method that takes four inputs parameters to represent the transaction's description, amount, date, and action (the parameters must be in that order). The method then creates an object of type Transaction and adds this object to the next available trans array location. Note that trans [O] must be filled before trans[1] and trans[1] must be filled before trans[2], etc. The method should return true if the transaction was added and false if the array was full and the transaction could not be added. getWithdrawalValue(): a method that calculates and returns the total value of all withdrawals in this statement getNumWithdrawals (): a method that returns the number of withdrawals in the statement get DepositValue(): A method that calculates and returns the total value of all deposits in this statement getNumDeposits(): a method that returns the number of deposits in the statement calculateInterest(): A static method that accepts two parameter, the interest rate (type double) and a statement. It calculates and returns the interest earned on the statement. getBalance(): a method that returns the current balance. getTransactions(): a method that returns the number of transactions in this statement toString(): a method that returns a string representation of the statement that includes the following: account holder's name, number of transactions in this statement, details of all the transactions, one per line the statement total before interest has been added, the amount of interest to be added, the statement total after interest has been added. NOTE: toString() should NOT change the balance Statement Driver class: Your driver class should do the following actions: Create two statements with your choice of account holder names and starting balances. Add three transactions to the first statement and two transactions to the second statement. Test WITHDRAWALS, DEPOSITS and INTEREST transactions. Set the interest rate to 4.5%. Print both invoices in a nicely formatted output. Your driver should also test all other aspects of your program (see p. 26-29 for a discussion of good testing). Do not use a Scanner to read any inputs from the user. Instead, use hard coded values for the different methods' inputs. Be sure to report an error when there is an attempt to add too many transactions to a statement

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Principles Programming And Performance

Authors: Patrick O'Neil

1st Edition

1558603921, 978-1558603929

More Books

Students also viewed these Databases questions

Question

4. Make sure students know if and when guessing is appropriate.

Answered: 1 week ago