0% found this document useful (0 votes)
56 views5 pages

Lab04 - An Account Management System

The document describes a lab assignment to create an account management system with two classes - Account and Transaction. The Account class represents bank accounts with methods like register, authenticate, showAccountDetails, and executeTransaction. The Transaction class represents deposit and withdrawal transactions with fields for transaction code and description. Students must implement the classes and methods according to the requirements and provide a test class to validate transactions on a sample account. The system should check authentication, update balances, and return error messages as specified.

Uploaded by

Vivian Chullamon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views5 pages

Lab04 - An Account Management System

The document describes a lab assignment to create an account management system with two classes - Account and Transaction. The Account class represents bank accounts with methods like register, authenticate, showAccountDetails, and executeTransaction. The Transaction class represents deposit and withdrawal transactions with fields for transaction code and description. Students must implement the classes and methods according to the requirements and provide a test class to validate transactions on a sample account. The system should check authentication, update balances, and return error messages as specified.

Uploaded by

Vivian Chullamon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

MTS280 2/2020

Lab04 – An Account Management System.

Objectives:
1. To practice using decision statements.
2. To learn how to work with more than one class and how the classes can be collaborated.

Requirements:
1. Working directory located at “C:\javalab”, and you should also set the working space in
Eclipse accordingly.
2. Create a project and name it as “XXXXXXXXXX_lab04”, where XXXXXXXXXX is
your student ID.
MTS280 2/2020

Section 1: Problem Statement.

Suppose that you are hired from a local bank to develop an easy management system for
client accounts. The system is quite straightforward, i.e., it has only two kinds of transactions
that can be carried out: deposit and withdraw.

Deposit transaction (transCode: DPST) is to deposit some money to a bank account, and
withdraw transaction (transCode: WTDW) is to withdraw some money from a bank account.

However, the bank strongly requires a security policy. That is, before any transaction is
performed on a specific account, the system should ask for username and password for a security
validation purpose. If the entered username and password are matched, the system updates the
details of the account accordingly and inform that the transaction is successfully done.
Otherwise, the system must refuse to perform the transaction and report the failure.

Section 2: System Design.

Your implementation should follow the class diagram below:

It has two classes: Account and Transaction. The class Account represents the bank
accounts which consist of three instance variables and four methods. The variables username
and password are used to store the authentication details for the bank account, and the variable
balance stores the current account balance so far.
The class Account also has four methods. The following table shows the requirements
of each method.

Method Name Requirement


CLASS: Account
register aims to set the details for the bank account in which it accepts
three parameters which are username, password, and
balance.
authenticate checks whether the entered username and password are
matched with the ones that were set by the method register or
not. If they are, the method returns true indicating the
authentication is successful; otherwise, it fails to authorize.
MTS280 2/2020

* When comparing the username and password, you cannot


ignore upper and lower cases.

showAccountDetails shows the report the current situation for the bank account. For
(*require authentication example, “Username:Thammasat, Balance:1000.0”. It accepts two
= if it fails to authorize, parameters for authentication purpose.
the transaction should be
cancelled)
executeTransaction aims to execute the specified transaction. It accepts four
(*require authentication parameters, the first two parameters (having types Transaction
= if it fails to authorize, and double respectively) indicate the transaction details to be
the transaction should be executed, and the remaining two are used for authentication
cancelled) purpose.

This method must check the type (transCode) of the specified


transaction, that is,

If the transCode is “DPST”, the system should top up the current


balance by the entered amount.

If the transCode is “WTDW”, the system should deduct the


current balance by the entered amount. In case that the account
has insufficient money, no deduction, inform error (i.e.,
insufficient balance) and return false.

Otherwise; the system should report that “invalid code.”.

* When comparing the transCode, you can ignore upper and


lower cases.

For the class Transaction, it has two variables transCode and description to
store the transaction code and description for a transaction. The two variables will be set by the
constructor. This class also provides two getter methods as indicated in the class diagram.

Section 3: Test class.

Here is the provided test class.

public class TestAccount {


public static void main(String args[]) {

String USER = "Thammasat";


String PASS = "TU2564";

Transaction tDep = new Transaction("DPST", "DEPOSIT");


Transaction tWit = new Transaction("WTDW", "WITHDRAW");
MTS280 2/2020

Account ac = new Account();


ac.register(0, "Thammasat", "TU2564");

ac.executeTransaction(tDep, 1000, USER, PASS);


ac.showAccountDetails(USER, PASS);

ac.executeTransaction(tWit, 1200, USER, PASS);


ac.showAccountDetails(USER, PASS);

ac.executeTransaction(tWit, 850, USER, PASS);


ac.showAccountDetails(USER, PASS);

ac.executeTransaction(tWit, 250, USER, PASS);


ac.showAccountDetails(USER, PASS);
}
}

Output (Console):

Trans Code DPST(DEPOSIT) with amount of 1000.0 has been successfully executed.
Username:Thammasat, Balance:1000.0
Trans Code WTDW(WITHDRAW) with amount of 1200.0 failed due to the insufficient
balance.
Username:Thammasat, Balance:1000.0
Trans Code WTDW(WITHDRAW) with amount of 850.0 has been successfully executed.
Username:Thammasat, Balance:150.0
Trans Code WTDW(WITHDRAW) with amount of 250.0 failed due to the insufficient
balance.
Username:Thammasat, Balance:150.0

In case you enter an invalid password (for example, setting String PASS = "tU2564"; instead
of PASS = "TU2564" in the test program above), your program should response as follows:

Authentication Failed.
Authentication Failed.
Authentication Failed.
Authentication Failed.
Authentication Failed.
Authentication Failed.
Authentication Failed.
Authentication Failed.
Authentication Failed.
Authentication Failed.

*** Students are encouraged to build the whole system on their own. However, we provide
partial codes such that you may consider them as a hint to start doing the lab. (the provided codes
can be found in lab04_hint.zip) ***

Submission:

Due date: within Feb 16, 2021 by 18:00


MTS280 2/2020

Submission channel:

Submit on Google classroom,


You are required to submit this lab as Eclipse project (compressed as .zip or .rar).
In this project, it must contain the following files:

1. Account.java
2. Transaction.java
3. TestAccount.java

You might also like