Bank/.DS_Store
__MACOSX/Bank/._.DS_Store
Bank/.classpath
Bank/.project
Bank
org.eclipse.jdt.core.javabuilder
org.eclipse.jdt.core.javanature
Bank/.settings/org.eclipse.jdt.core.prefs
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=14
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=14
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=14
Bank/src/.DS_Store
__MACOSX/Bank/src/._.DS_Store
Bank/src/Answer files.zip
Answer files/AccountDetails.txt
ACC12345
Harry Potter
Answer files/TransactionStatus.java
Answer files/TransactionStatus.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.mycompany.week8_tbalbi_swen646;
/**
*
* @author Teeh
*/
public enum TransactionStatus
{
Draft,
Complete;
}
__MACOSX/Answer files/._TransactionStatus.java
Answer files/OwnerInformation.java
Answer files/OwnerInformation.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.mycompany.week8_tbalbi_swen646;
/**
*
* @author Teeh
*/
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
public class OwnerInformation {
private String name;
private MailingAddress mailingAddress;
private String email;
private int phoneNumber;
public String toString() {
return "
" + "" + name + "" + this.mailingAddress.toString() + "" + email + "" + "" + String.valueOf(phoneNumber) + "" + "";
}
public OwnerInformation clone() {
OwnerInformation owner_clone = new OwnerInformation(this.name, this.mailingAddress, this.email, this.phoneNumber);
return owner_clone;
}
public OwnerInformation(String name, MailingAddress mailingAddress, String email, int phoneNumber) {
// validate that none of the parameter values are null or empty strings
if (name == null || mailingAddress == null || email == null)
throw new IllegalArgumentException("Parameter values cannot be null or empty strings");
this.name = name;
this.mailingAddress = mailingAddress;
this.email = email;
this.phoneNumber = phoneNumber;
}
public String getName() {
return name;
}
public MailingAddress getMailingAddress() {
return mailingAddress;
}
public String getEmail() {
return email;
}
public int getPhoneNumber() {
return phoneNumber;
}
public void setMailingAddress(MailingAddress mailingAddress) {
//validate that parameter is not null or empty
if (mailingAddress == null)
throw new IllegalArgumentException("Parameter value cannot be null or empty");
this.mailingAddress = mailingAddress.clone(); // assign clone so caller cannot change directly
}
public void setEmail(String email) {
//validate that parameter is not null or empty String
if (email ==null || email.length() == 0)
throw new IllegalArgumentException("Parameter value cannot be null or empty");
this.email = email;
}
public void setPhoneNumber(int phoneNumber) {
//validate that parameter is not null or empty
if(phoneNumber <=0)
throw new IllegalArgumentException("Parameter value cannot be null or empty");
this.phoneNumber = phoneNumber;
}
public void setName(String name) {
//validate that parameter is not null or empty String
if (name ==null || name.length() == 0)
throw new IllegalArgumentException("Parameter value cannot be null or empty");
this.name = name;
}
public OwnerInformation(String fileName) throws Exception {
// validate fileName
File f = new File(fileName);
if(!f.exists() ||f.isDirectory())
throw new InvalidLoadException(fileName, "Filename is not valid.");
else
{
BufferedReader reader = new BufferedReader(new FileReader(fileName));
this.name= reader.readLine();
this.mailingAddress = new MailingAddress(reader.readLine(), reader.readLine(), reader.readLine(), reader.readLine());
this.email = reader.readLine();
this.phoneNumber = Integer.valueOf(reader.readLine());
reader.close();
}
}
}
__MACOSX/Answer files/._OwnerInformation.java
Answer files/DuplicateObjectException.java
Answer files/DuplicateObjectException.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.mycompany.week8_tbalbi_swen646;
/**
*
* @author Teeh
*/
public class DuplicateObjectException extends RuntimeException {
private String acIdNumber;
private String trIdNumber;
private int constructor_id;
public String toString() {
if(this.constructor_id == 0)
return this.getClass().getName() + ": This account id number already exists: " + acIdNumber;
else
return this.getClass().getName() + ": This transaction id number already exists: " + acIdNumber + trIdNumber;
}
public DuplicateObjectException(String acIdNumber)
{
super("This account id number already exists " + acIdNumber);
this.constructor_id = 0;
this.acIdNumber = acIdNumber;
}
public DuplicateObjectException(String acIdNumber, String trIdNumber) {
super("This transaction id number already exists " + trIdNumber + acIdNumber);
this.acIdNumber = acIdNumber;
this.trIdNumber = trIdNumber;
this.constructor_id = 1;
}
}
__MACOSX/Answer files/._DuplicateObjectException.java
Answer files/TestCases.java
Answer files/TestCases.java
import java.util.Scanner;
package com.mycompany.week8_tbalbi_swen646;
public class TestCases
{
public static void displayMessage(String message, boolean success)
{
if(success)
System.out.println("SUCCESS: " + message);
else
System.out.println("ERROR: " + message);
}
public static void displayTestCaseHeader(String header)
{
System.out.println("TEST: " + header);
String lines = "------";
for(int i = 0; i < header.length(); i++)
System.out.print("-");
System.out.println(lines);
}
public static Account load_accounts_test()
{
displayTestCaseHeader("Load accounts successfully");
Scanner scan = new Scanner(System.in);
System.out.print("Enter filename with account details: ");
String fileName = scan.nextLine();
Account a;
try
{
a = new Account(fileName);
if(AccountStatus.Active == a.getAccountStatus())
displayMessage("Account details loaded successfully", true);
else
displayMessage("Account details not loaded successfully", false);
return a;
}
catch (Exception e)
{
displayMessage("Tests could not be done.", false);
e.printStackTrace();
return null;
}
}
public static void add_remove_transaction_to_account(Account a)
{
displayTestCaseHeader("Add transactions successfully");
// Create a transaction
// and add it to the account
Transaction t = new Transaction("T1", "Test transaction");
a.addTransaction(t);
// Now, try to retrieve it.
Transaction tr = a.retrieveTransaction("T1");
// Print the appropriate message
if(tr != null)
{
displayMessage("Transaction added to account successfully", true);
displayTestCaseHeader("Remove transactions successfully");
// Try to remove the transaction
a.removeTransaction("T1");
tr = a.retrieveTransaction("T1");
if(tr != null)
displayMessage("Transaction couldn't be removed from the account", false);
else
displayMessage("Transaction successfully removed from the account", true);
}
else
displayMessage("Transaction couldn't be added to the account", false);
}
public static void remove_transaction_from_complete_account(Account a)
{
displayTestCaseHeader("Remove transaction from complete account");
Scanner scan = new Scanner(System.in);
System.out.print("Enter filename that has a complete transaction details: ");
String fileName = scan.nextLine();
Transaction completeTransaction;
try
{
completeTransaction = new Transaction(fileName);
a.addTransaction(completeTransaction);
String id = completeTransaction.getTransIdNumber();
a.removeTransaction(id);
Transaction tr = a.retrieveTransaction(id);
if(tr == null)
displayMessage("Transaction couldn't be removed from the account", true);
else
displayMessage("Transaction was removed from the account", false);
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void retrieve_account_using_number(Account a)
{
Scanner scan = new Scanner(System.in);
System.out.print("Enter directory name: ");
String dir = scan.nextLine();
try
{
Manager m = new Manager(dir);
Account b = m.retrieveAccount(a.getAcctIdNumber());
if(b == null)
displayMessage("Account couldn't be retrieved using number", false);
else
displayMessage("Account successfully retrieved using number", true);
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void retrieve_inactive_account()
{
Scanner scan = new Scanner(System.in);
System.out.print("Enter directory name with inactive account details: ");
String dir = scan.nextLine();
try
{
Manager m = new Manager(dir);
System.out.print("Enter account number of the inactive account: ");
String actNumber = scan.nextLine();
Account b = m.retrieveAccount(actNumber);
if(b == null)
displayMessage("Inactive account couldn't be retrieved using number", true);
else
displayMessage("Inactive account was retrieved using number", false);
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void retrieve_complete_transaction()
{
if(false)
displayMessage("Complete transaction was retrieved", false);
else
displayMessage("Complete transaction couldn't retrieved", true);
}
public static void main(String[] args)
{
Account a = load_accounts_test();
add_remove_transaction_to_account(a);
remove_transaction_from_complete_account(a);
retrieve_account_using_number(a);
retrieve_inactive_account();
retrieve_complete_transaction();
}
}
Answer files/Manager.java
Answer files/Manager.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.mycompany.week8_tbalbi_swen646;
/**
*
* @author Teeh
*/
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Vector;
public class Manager
{
private Vector
accounts;
private String directory;
public void acctSaveToFile(String acctIdNumber)
{
try
{
FileWriter writer = new FileWriter("account-id-" + acctIdNumber + ".xml");
for(Account acc: accounts)
{
if(acc.getAcctIdNumber().equals(acctIdNumber))
writer.write(acc.toString());
}
writer.close();
}
catch(IOException ex)
{
ex.printStackTrace();
}
}
public int addAcct(Account account)
{
if(account == null)
throw new IllegalArgumentException("Parameter values cannot be null");
else
{
// check that the accIdNumber does not exists
for(Account acc: accounts)
{
if(acc.getAcctIdNumber().equals(account.getAcctIdNumber()))
throw new DuplicateObjectException(account.getAcctIdNumber(), " This account id number already exists");
else
{
this.accounts.add(account.clone());
return accounts.size();
}
}
}
return 0;
}
public Account retrieveAccount(String acctIdNumber) {
for(Account acc: accounts)
{
if(acc.getAcctIdNumber().equals(acctIdNumber))
return acc;
}
return null;
}
public Manager(String directory) throws Exception
{
//check if directory is null
if (directory == null)
throw new NullPointerException("Directory is null");
// check if diretory is not empty
if(directory.isEmpty())
{
throw new InvalidLoadException(directory, "Directory not found.");
}
else
{
Path path = Paths.get(directory);
File file = new File(directory);
if(!Files.exists(path) || !file.isDirectory())
throw new InvalidLoadException(directory, "Loading directory failed");
else
{
this.directory = directory;
this.accounts = new Vector();
// get list of all files
File directoryPath = new File(getDirectory());
//List of all files and directories
String contents[] = directoryPath.list();
for(int i=0; i {
Account acc = new Account(contents[i]);
// search transactions for this account
for(int j = 0; j {
String name = contents[j];
if(name.substring(0, 7).compareTo("trans-id") == 0) // it's a transaction file
{
String[] dat = name.split("-");
String acc_number = dat[5];
if(acc_number.compareTo(acc.getAcctIdNumber()) == 0)
{
// load transaction
Transaction t = new Transaction(name);
acc.addTransaction(t);
}
}
}
}
}
}
}
public Vector getAccounts()
{
return accounts;
}
public String getDirectory()
{
return directory;
}
}
__MACOSX/Answer files/._Manager.java
Answer files/MailingAddress.java
Answer files/MailingAddress.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.mycompany.week8_tbalbi_swen646;
/**
*
* @author Teeh
*/
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public class MailingAddress {
private String street;
private String city;
private String state;
private String zip;
public String toString() {
return "" + "" + street + "" + "" + city + "" + "" + state + "" + "" + zip + "" + "";
}
public MailingAddress clone() {
MailingAddress ma_clone = new MailingAddress(this.street, this.city, this.state, this.zip);
return ma_clone;
}
public MailingAddress(String street, String city, String state, String zip) {
// validate that none of the parameter values are null or empty strings
if (street == null || city == null || state == null || zip == null
|| street.length() == 0 || city.length() == 0 || state.length() == 0 || zip.length() == 0)
throw new IllegalArgumentException("Parameter values cannot be null or empty strings");
this.street = street;
this.city = city;
this.state = state;
this.zip = zip;
}
public String getStreet() {
return street;
}
public String getCity() {
return city;
}
public String getState() {
return state;
}
public String getZip() {
return zip;
}
public void setStreet(String st) {
if(st.isEmpty())
throw new IllegalArgumentException("Parameter values cannot be null");
this.street = st;
}
public void setCity(String ct) {
if(ct.isEmpty())
throw new IllegalArgumentException("Parameter values cannot be null");
this.city = ct;
}
public void setState(String sta) {
if(sta.isEmpty())
throw new IllegalArgumentException("Parameter values cannot be null");
this.state = sta;
}
public void setZip(String zip) {
if(zip.isEmpty())
throw new IllegalArgumentException("Parameter values cannot be null");
this.zip = zip;
}
public MailingAddress(String fileName) throws IOException {
// validate fileName
File f = new File(fileName);
if(!f.exists() ||f.isDirectory())
throw new InvalidLoadException(fileName, "Filename is not valid.");
else
{
BufferedReader reader = new BufferedReader(new FileReader(fileName));
this.street = reader.readLine();
this.city = reader.readLine();
this.state = reader.readLine();
this.zip = reader.readLine();
reader.close();
}
}
}
__MACOSX/Answer files/._MailingAddress.java
Answer files/InvalidOperationException.java
Answer files/InvalidOperationException.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.mycompany.week8_tbalbi_swen646;
/**
*
* @author Teeh
*/
public class InvalidOperationException extends RuntimeException {
private String transId; //This is an object type string that provides transaction Id number.
private String reasonFailed; //This is an object type string that provides the reason a trans Id failed
private String acctIdNumber;
public String toString() {
return this.getClass().getName() + ": Removing transaction failed " + acctIdNumber + transId + " " + " " + reasonFailed;
}
public InvalidOperationException(String acctIdNumber, String transId, String reasonFailed) {
super("Removing transaction failed" + acctIdNumber + transId + reasonFailed);
this.acctIdNumber = acctIdNumber;
this.transId = transId;
this.reasonFailed = reasonFailed;
}
}
__MACOSX/Answer files/._InvalidOperationException.java
Answer files/Account.java
Answer...