Using the attached code, I need to create a single test case only with each scenario a separate method called from main. I must have at minimum code test cases to verify the major functionality of the...

1 answer below »
Using the attached code, I need to create a single test case only with each scenario a separate method called from main.
I must have at minimum code test cases to verify the major functionality of the system:
- successfully loading account and transaction data on startup and throwing exception on errors;- Inactivating and reactivating an account

- Completing a transaction

- Adding new transaction to an account

- Removing transaction from an account

- Failing to remove a transaction from an account if status is complete

- Retrieving account using account id number

- Failing to retrieve an account if status is inactive

- Retrieving transaction using transaction id number

- Failing to retrieve a transaction if status is complete

- Changing draft transaction

- Retrieve transaction cost for a draft transaction
Make sure you use comments to document what each test case is verifying and doing. Your tests must either dynamically verify that they are successful or print data to the screen that can be manually checked to verify.
Feel free to modify the code to meet test requirements, if code is not working


OOP Project Description Requirements: You are to design and build prototype software (stand-alone application loaded on business’s local computer) to manage accounts and their transactions. Your software will be used and called by User Interface (UI) that someone else will be implementing. You will get to design the UI in software design document (SDD) but you will not be implementing it for this project. You can assume that the UI layer will be vendor’s code and packaged in a separate package than your system. Your software will load all the existing account and transactions data on startup. For this project, the data will be loaded and saved in text files on the local system (for the final product outside the scope of this project, server with database will be used) with each account and transaction saved in a separate file. UI will provide the directory of where the files will be located but the actual filename convention will be hard-coded in your Manager class and UI will not interact directly with the data storage (only through your systems’ methods). Your system will manage all the data and it has to update the files as needed to keep them current at all times. When the system starts up, UI will create an instance of your Manager class and pass it the directory where the accounts and transaction files are located. Your system will then load all the account and their corresponding transactions data. Account information will be stored with filename convention: account-id-number.txt and transactions will be stored using the filename convention of: trans-id-number-acc-id-number.txt (you can use .json or .xml extensions instead) where id-number is a unique id value for the account and for transaction ids. You can hardcode subdirectory structure and directory naming convention as you wish. After the accounts and transaction data is loaded on system startup (creation of manager instance), the user (using UI) will be able to get the list of accounts with their transactions. In addition, your system needs to provide the functionality to add new account to manager, inactivate an existing account, reactivate an account that is currently inactive, add transaction to an account, remove a transaction from an account, complete a transaction, retrieve an account for a specific id from manager, retrieve transaction from an account for a specific transaction id, and to calculate transaction cost for a draft transaction. In addition, all classes except Manager need a toString() method to return class’s formatted data that can be written to the console (or file). You can assume that the number of current accounts and transactions is small enough to load all into memory on startup. Note that UI will handle the login and authorization and access control but all are outside of the scope of the system you are designing. An account includes the following information: unique id number (String), owner information (name, mailing address, email, and phone number), list of transaction objects for that account, and status whether the account is active or inactive. When a new account is created, it must be provided id and owner information, the transaction list will be empty, and the account will be active. No duplicate accounts based on id number are allowed in manager. An account cannot be removed, only inactivated. No data can be changed for an inactive account. Once a transaction is completed, it cannot be removed from the account. The account id cannot be ever changed and status can only be changed by the inactivate/reactivate action. There are three different types of transactions allowed: purchase, travel, and rent. Each transaction object includes unique id number (String), transaction cost, date the transaction was completed (Date or Calendar) description (max 500 characters), and status (draft or completed). In addition, purchase transaction objects also have the number of items being purchased and price per item; travel transaction has the travel total cost; and rent transaction has number of days for the rental and the daily rate of the rental. Transaction object cannot exist without all the values and all values can be changed through this system except transaction id. On creation, the date of transaction is set to null, transaction cost is 0, and status is draft. These values can only be set when transaction is completed. No transaction data can be changed once transaction is completed nor can it be removed from the account and transaction cannot be reversed back to draft. Transaction cost includes a flat fee of $2.99 plus transaction specific cost calculated as follows. (1) Travel transaction: flat fee plus the travel cost (2) Purchase transaction: flat fee plus the number of items multiplied by price per item (3) Rent transaction: flat fee plus the number of days multiplied by daily rate When the account or transaction data is changed, system must update the appropriate files. It is up to you what format you use for the account and transaction files but they must be human readable text files. Your design and code must follow separation of concerns principle, so a class cannot parse nor load another classes attributes (it need to call that other classes constructor/method to do it) . You can use XML tags (you can model after Trip example) or JSON or other text formats you are familiar with or would like to use. Your system will need the following exceptions and validation to be added for the week 5 assignment: 1. When loading accounts and transactions and file(s) do not exist or there is any issue parsing file or accounts/transaction data, throw unchecked user defined exception called InvalidLoadException when violation detected. The exception will extend RuntimeException. The exception message should indicate what the detected issue was and the filename that could not be loaded or data that could not be parsed. 2. On adding account or adding transaction to an account, if duplicate account/transaction exists throw unchecked user defined exception called DuplicateObjectException when violation detected. The exception will extend RuntimeException. The generated exception message should indicate the id of the account and/or transaction and why it failed. 3. On removing transaction, if it cannot be removed for any other reason, throw unchecked user defined exception called InvalidOperationException when violation detected. The exception will extend RuntimeException. The generated exception message should indicate the id of the transaction and reason why it failed. 4. On all other issues use Java builtin exceptions such as InvalidArgumentException for parsing/validation issues and IllegalStateException with meaningful messages UI is outside the scope of your design but your system needs to have all the functionality that UI needs to satisfy the project requirements. As you design the system, you need to make sure it is consistent and it only has the interfaces (constructors, attributes and methods) that are needed by the required functionality. You cannot arbitrarily add new functionality to the system. The system you are designing will have the functionality needed to satisfy the above requirements. You will NOT be implementing the actual user interface (you will still design it though in your Software Design Document in later assignment) but you need the classes, attributes, and methods to receive and provide the information that the user interface will need. You can assume that for a complete solution there would be some other class that implements user interface (UI) with main() method and that it will call your classes/methods. Your system will not have main method except in the test class. When you implement the system, you must have at minimum code test cases to verify the major functionality of the system: successfully loading account and transaction data on startup and throwing exception on errors; successfully inactivating and reactivating an account; successfully adding new transaction to an account; successfully completing a transaction; successfully removing transaction from account and failing if already completed; successfully retrieving an account for a specific id and throwing exception if it does not exist; successfully retrieving a transaction for an account for a specific id and throwing exception if it does not exist; throwing an exception if try to update completed transaction or for inactive account; successfully changing draft transaction; retrieve transaction cost for a draft transaction; and test case to verify that files are updated when account or transaction data changes. There should be a single test class with main method and each test case scenario should be a separate method called by the main. Make sure you use comments to document what each test case is verifying and doing. Your tests must either dynamically verify that they are successful or print data to the screen that can be manually checked to verify. Week8_TBalbi_SWEN646/pom.xml 4.0.0 com.mycompany Week8_TBalbi_SWEN646 1.0-SNAPSHOT jar UTF-8 16 16 Week8_TBalbi_SWEN646/src/main/java/com/mycompany/week8_tbalbi_swen646/Account.java Week8_TBalbi_SWEN646/src/main/java/com/mycompany/week8_tbalbi_swen646/Account.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; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.Calendar; import java.util.Vector; import java.util.Collections; public class Account {   private String acctIdNumber;   private OwnerInformation ownerinformation;   private AccountStatus accountStatus;   private Vector  transactions;   public String toString() {       return "" + "" + acctIdNumber + "" + ownerinformation.toString() + "" + accountStatus + "" + "";   }   public int addTransaction(Transaction transaction) {       if(transaction == null)       throw new IllegalArgumentException("Parameter values cannot be null");           if(getAccountStatus().equals(AccountStatus.Inactive))       throw new IllegalStateException("Account is inactive and cannot be changed");     else     {       // check transaction number       for(Transaction t: transactions)       {         if(t.getTransIdNumber().equals(transaction.getTransIdNumber()))           throw new DuplicateObjectException("This transaction id number already exists", transaction.getTransIdNumber());       }       this.transactions.add(transaction.clone());            }     return transactions.size();   }   public Account clone() {       // create new object     Account acc_clone = new Account(getAcctIdNumber(), getOwnerInformation());     acc_clone.accountStatus = getAccountStatus();     acc_clone.transactions = getTransactions();     return acc_clone;   }   public void removeTransaction(String transIdNumber) {     if(getAccountStatus().equals(AccountStatus.Inactive))       throw new IllegalStateException("Account is inactive and cannot be changed");          Transaction transaction = null;     int index = -1;     for(Transaction t: transactions)     {       if(t.getTransIdNumber().equals(transIdNumber))       {         transaction = t;         break;       }       index++;     }     if(transaction != null)     {       // check if transaction has not been completed       if(transaction.getTransactionStatus().equals(TransactionStatus.Complete))         throw new InvalidOperationException(transIdNumber, " ", "Transaction has been completed and cannot be modified.");       transactions.remove(index);       File file = new File("trans-id-" + transaction.getTransIdNumber() + ".xml");       file.delete();     }     else       throw new IllegalArgumentException("Parameter values cannot be null");        }   public Transaction retrieveTransaction(String transIdNumber) {       if(getAccountStatus().equals(AccountStatus.Inactive))       throw new IllegalStateException("Account is inactive and cannot be changed");     for(Transaction t: transactions)     {       if(t.getTransIdNumber().equals(transIdNumber))         return t;     }     return null;   }   public void transSaveToFile(String transIdNumber) {     try     {       FileWriter writer = new FileWriter("trans-id-" + transIdNumber + "-acct-id-" + acctIdNumber + ".xml");       for(Transaction t: transactions)       {         if(t.getTransIdNumber().equals(transIdNumber))           writer.write(t.toString());       }       writer.close();     }     catch(IOException ex)     {       ex.printStackTrace();     }   }   public void completeTransaction(String transIdNumber) {     Transaction t = retrieveTransaction(transIdNumber);     if(t == null)       throw new IllegalArgumentException("Parameter values cannot be null");     if(getAccountStatus().equals(AccountStatus.Inactive))       throw new IllegalStateException("Account is inactive and cannot be changed");     t.transactionStatus = TransactionStatus.Complete;     t.finalTotalCost = t.calculateFinalTotalCost();     t.dateOfTrans = Calendar.getInstance();   }   public Vector  getTransactions() {       return transactions;   }   public Account(String acctIdNumber, OwnerInformation ownerInformation) {     // validate parameters     if(acctIdNumber == null ||ownerInformation == null)       throw new IllegalArgumentException("Parameter values cannot be null");     else     {       this.transactions = new Vector();       this.acctIdNumber = acctIdNumber;       this.ownerinformation = ownerInformation;       this.accountStatus = AccountStatus.Active;       Collections.emptyList();                   }   }   public String getAcctIdNumber() {       return acctIdNumber;   }   public OwnerInformation getOwnerInformation() {       return ownerinformation;   }   public void setOwnerInformation(OwnerInformation info) {     if(getAccountStatus().equals(AccountStatus.Inactive))       throw new IllegalStateException("Account is inactive and cannot be changed");     ownerinformation = info;   }   public AccountStatus getAccountStatus() {       return accountStatus;   }   public Account(String fileName) throws Exception {     // validate fileName     File f = new File(fileName);     if(!f.exists() ||f.isDirectory())       throw new InvalidLoadException(fileName, "Filename is not valid.");     if(getAccountStatus().equals(AccountStatus.Inactive))       throw new IllegalStateException("Account is inactive and cannot be changed");     else     {         this.transactions = new Vector();         BufferedReader reader = new BufferedReader(new FileReader(fileName));         // read first line         String line = reader.readLine();         this.acctIdNumber = line;         OwnerInformation info = new OwnerInformation (line.substring(line.indexOf("") + 10, line.indexOf("")));                                             this.ownerinformation = info;         this.accountStatus = AccountStatus.Active;         reader.close();     }        }   public void editAccount(Account account) {     if(account == null)       throw new IllegalArgumentException("Parameter values cannot be null");     if(getAccountStatus()
Answered 3 days AfterJul 22, 2021

Answer To: Using the attached code, I need to create a single test case only with each scenario a separate...

Arun Shankar answered on Jul 25 2021
141 Votes
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...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here