Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are required to create two classes, a Transaction class modeled after a banking situation and the main class (containing the main method). Please closely

You are required to create two classes, a Transaction class modeled after a banking situation and the main class (containing the main method).

Please closely follow the requirements below.

Requirements for the Transaction class:

A private data field named as date (of Date data type), representing the date of the transaction

A private data field named as type (of char data type), representing the type of the transaction, such as W for withdrawal and D for deposit

A private data field named as amount (of double data type), representing the amount of the transaction

A private data field named as balance (of double data type), representing the balance of the account after the transaction

A private data field named as description (of String data type), representing the description of the transaction

A constructor that creates an instance of the Transaction class with specified values of transaction type, amount, balance, and description, and date of the transaction.

Note: Instead of passing a Date object to the constructor, you should use the new operator inside the body of the constructor to pass a new Date instance to the date data field (as we did for the Account class in class).

Define the corresponding accessor (get) methods to access a transactions date, type, amount, description, and the balance, i.e., you need to define 5 get methods.

Define a toString() method which does not receive parameters but returns a String that summarizes the transaction details, including transaction type, amount, balance after transaction, description of the transaction, and transaction date.

You can organize and format the returned String in your own way, but you must include all of the required information.

Note: the purpose of the Transaction class is to document a banking transaction, i.e., when a transaction happens, you can use the transaction parameters to create an instance of the Transaction class.

Requirements for the main class: To test the Transaction class, in the main method of your main class you need to do the following:

Create two instances of the Transaction class that represent the following transactions: o transaction 1: type: deposit; amount: 50; balance: 1050; description: babysitting income o transaction 2: type: withdraw; amount: 30; balance: 1020; description: tennis fee

Call the toString method of the Transaction class to print out a summary of each transaction.

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

Students also viewed these Databases questions