Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your task is to develop a simple online banking system. There are: Two exceptions classes: UserException FundsException Two backend classes: User BankAccount One frontend class:

Your task is to develop a simple online banking system. There are:

Two exceptions classes:

UserException

FundsException

Two backend classes:

User

BankAccount

One frontend class:

GUI

UserException and FundsException both subclass Exception, and are already implemented.

Your task is to complete User, BankAccount, and GUI by using object-oriented programming, and exception throwing & handling.

You will need to create a static ArrayList named usernames in the User class to maintain a list of usernames that have been taken:

 
 
static ArrayList usernames = new ArrayList(); 

Note that a try/catch must be used in the GUI class to gracefully handle potential exceptions. You should not rethrow exceptions in the GUI.

Finally, upload and submit your 5 classes:

BankAccount

FundsException

GUI

User

UserException BANKACCOUNT.JAVA CODE BELOW -

package coll.UserAccounts;

public class BankAccount {

/**

* Constructs a bank object with $0.0 funds and assigns the given User as the

* owner.

* @param owner

*/

public BankAccount(User owner) {

}

/**

* Gets the total funds in the account.

* @return

*/

public double getFunds() {

return 0;

}

/**

* Deposits money into the account.

* @param deposit. The sum of money in $ to be deposited.

*/

public void deposit(double deposit) {

}

/**

* Withdraws money from the account. Only the owner can withdraw funds.

* @param user. The user attempting to withdraw funds.

* @param withdrawal. The amount to be withdrawn.

* @throws UserException if anyone but the owner is attempting to withdraw fundss.

* @throws FundsException if there are insufficient funds in the account.

*/

public void withdraw(User user, double withdrawal) throws UserException, FundsException {

}

} FUNDSEXCEPTION.JAVA CODE BELOW -

package coll.UserAccounts;

public class FundsException extends Exception {

}

GUI.JAVA CODE BELOW -

package coll.UserAccounts;

/**

* Exists as a primitive front-end for the User and BankAccount classes.

*/

public class GUI {

/**

* Transfers money from one account to another. If the withdraw fails due to a

* UserException then print "Unauthorized access!" If the withdraw fails due to

* a FundsException then print "Insufficient funds!"

*

* @param user. The user that is attempting to execute the transfer.

* @param b1. The bank account that the funds are being transferred from.

* @param b2. The bank account that the funds are being transferred to.

* @param amount. The amount of money to be transferred in $.

*/

public static void transfer(User user, BankAccount b1, BankAccount b2, double amount) {

}

} USER.JAVA CODE BELOW -

package coll.UserAccounts;

public class User {

/**

* Constructs a user with a given username and password. If a user is

* successfully constructed, their username is added to the list of usernames.

*

* @param username

* @param password

* @throws Exception.

* Throws a UserException if the username or password is invalid

* (use the below methods badUsername and badPassword to assist you

* with this).

*/

public User(String username, String password) throws Exception {

}

/**

* Gets the username of the user.

*

* @return

*/

public String getUsername() {

return null;

}

/**

* Gets the password of the user.

*

* @return

*/

public String getPassword() {

return null;

}

/**

* Checks if a given username is invalid

*

* @param username

* @return true if the username already exist, false otherwise.

*/

public static boolean badUsername(String username) {

return false;

}

/**

* Checks if a given password is invalid.

*

* @param password

* @return true if the password is fewer than 8 characters long, false

* otherwise.

*/

public static boolean badPassword(String password) {

return false;

}

}

USEREXCEPTION.JAVA CODE BELOW -

package coll.UserAccounts;

public class UserException extends Exception {

}

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

Marketing Database Analytics

Authors: Andrew D. Banasiewicz

1st Edition

0415657881, 978-0415657884

More Books

Students also viewed these Databases questions