Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
4973d45198 | ||
|
65963450ab |
21
.vscode/launch.json
vendored
Normal file
21
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "java",
|
||||
"name": "Current File",
|
||||
"request": "launch",
|
||||
"mainClass": "${file}"
|
||||
},
|
||||
{
|
||||
"type": "java",
|
||||
"name": "BankAcctApp",
|
||||
"request": "launch",
|
||||
"mainClass": "bankAcctApp.BankAcctApp",
|
||||
"projectName": "Bank Account App_b3cd1e26"
|
||||
}
|
||||
]
|
||||
}
|
BIN
bin/bankAcctApp/Account.class
Normal file
BIN
bin/bankAcctApp/Account.class
Normal file
Binary file not shown.
BIN
bin/bankAcctApp/AccountInterface.class
Normal file
BIN
bin/bankAcctApp/AccountInterface.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
bin/bankAcctApp/CheckingAccount.class
Normal file
BIN
bin/bankAcctApp/CheckingAccount.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
bin/bankAcctApp/SavingsAccount.class
Normal file
BIN
bin/bankAcctApp/SavingsAccount.class
Normal file
Binary file not shown.
102
src/bankAcctApp/Account.java
Normal file
102
src/bankAcctApp/Account.java
Normal file
@@ -0,0 +1,102 @@
|
||||
/* Phase III */
|
||||
|
||||
package bankAcctApp;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
// Abstract class defining the structure for account types
|
||||
public abstract class Account implements AccountInterface {
|
||||
private String accountNumber; // Account number for each account
|
||||
private String accountType; // Type of account (CHK or SAV)
|
||||
private double svcFee; // Service fee for transactions
|
||||
private double interestRate; // Interest rate for the account
|
||||
private double overDraftFee; // Overdraft fee for checking accounts
|
||||
private double balance = 0.00; // Initial balance of the account
|
||||
|
||||
// Transaction history stored as strings
|
||||
private ArrayList<String> transactionHistory = new ArrayList<>();
|
||||
|
||||
// Getter for account number
|
||||
public String getAccountNumber() {
|
||||
return accountNumber;
|
||||
}
|
||||
|
||||
// Setter for account number
|
||||
public void setAccountNumber(String accountNumber) {
|
||||
this.accountNumber = accountNumber;
|
||||
}
|
||||
|
||||
// Getter for account type
|
||||
public String getAccountType() {
|
||||
return accountType;
|
||||
}
|
||||
|
||||
// Setter for account type
|
||||
public void setAccountType(String accountType) {
|
||||
this.accountType = accountType;
|
||||
}
|
||||
|
||||
// Getter for service fee
|
||||
public double getSvcFee() {
|
||||
return svcFee;
|
||||
}
|
||||
|
||||
// Setter for service fee
|
||||
public void setSvcFee(double svcFee) {
|
||||
this.svcFee = svcFee;
|
||||
}
|
||||
|
||||
// Getter for interest rate
|
||||
public double getInterestRate() {
|
||||
return interestRate;
|
||||
}
|
||||
|
||||
// Setter for interest rate
|
||||
public void setInterestRate(double interestRate) {
|
||||
this.interestRate = interestRate;
|
||||
}
|
||||
|
||||
// Getter for overdraft fee
|
||||
public double getOverDraftFee() {
|
||||
return overDraftFee;
|
||||
}
|
||||
|
||||
// Setter for overdraft fee
|
||||
public void setOverDraftFee(double overDraftFee) {
|
||||
this.overDraftFee = overDraftFee;
|
||||
}
|
||||
|
||||
// Getter for account balance
|
||||
public double getBalance() {
|
||||
return balance;
|
||||
}
|
||||
|
||||
// Setter for account balance
|
||||
public void setBalance(double balance) {
|
||||
this.balance = balance;
|
||||
}
|
||||
|
||||
// Getter for transaction history
|
||||
public ArrayList<String> getTransactionHistory() {
|
||||
return transactionHistory;
|
||||
}
|
||||
|
||||
// Method to log a transaction and store it in the transaction history
|
||||
public String logTransaction(String date, String type, double amount) {
|
||||
String transaction = String.format(
|
||||
"Date: %s | Type: %s | Amount: $%.2f | Balance: $%.2f",
|
||||
date, type, amount, this.balance
|
||||
);
|
||||
transactionHistory.add(transaction); // Add transaction to history
|
||||
return transaction; // Return the formatted transaction string
|
||||
}
|
||||
|
||||
// Abstract method for withdrawals, to be implemented in subclasses
|
||||
public abstract void withdrawal(double amount);
|
||||
|
||||
// Abstract method for deposits, to be implemented in subclasses
|
||||
public abstract void deposit(double amount);
|
||||
|
||||
// Abstract method for applying accrued interest
|
||||
public abstract double applyAccruedInterest(String transactionDate);
|
||||
}
|
10
src/bankAcctApp/AccountInterface.java
Normal file
10
src/bankAcctApp/AccountInterface.java
Normal file
@@ -0,0 +1,10 @@
|
||||
/* Phase III */
|
||||
|
||||
package bankAcctApp;
|
||||
|
||||
public interface AccountInterface {
|
||||
void withdrawal(double amount);
|
||||
void deposit(double amount);
|
||||
double applyAccruedInterest(String date);
|
||||
double balance();
|
||||
}
|
@@ -1,40 +1,344 @@
|
||||
/* Phase III */
|
||||
|
||||
package bankAcctApp;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BankAcctApp {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
ArrayList<Customer> customers = new ArrayList<>();
|
||||
ArrayList<Account> accounts = new ArrayList<>();
|
||||
boolean moreCustomers = true;
|
||||
|
||||
// Add customers and accounts
|
||||
while (moreCustomers) {
|
||||
Customer customer = new Customer();
|
||||
Account account = null;
|
||||
int inputCount = 0;
|
||||
|
||||
System.out.println("Enter details for new customer:\n");
|
||||
|
||||
// Collect and validate customer ID
|
||||
while (inputCount == 0) {
|
||||
try {
|
||||
customer.setID(DataEntry.inputStringWithLimit("Customer ID (max 5 chars): ", 5));
|
||||
customer.setSSN(DataEntry.inputNumericString("SSN (9 numeric chars): ", 9));
|
||||
customer.setLastName(DataEntry.inputStringWithLimit("Last Name (max 20 chars): ", 20));
|
||||
customer.setFirstName(DataEntry.inputStringWithLimit("First Name (max 15 chars): ", 15));
|
||||
customer.setStreet(DataEntry.inputStringWithLimit("Street (max 20 chars): ", 20));
|
||||
customer.setCity(DataEntry.inputStringWithLimit("City (max 20 chars): ", 20));
|
||||
customer.setState(DataEntry.inputStringWithLimit("State (2 chars): ", 2));
|
||||
customer.setZip(DataEntry.inputNumericString("Zip (5 numeric chars): ", 5));
|
||||
customer.setPhone(DataEntry.inputNumericString("Phone (10 numeric chars): ", 10));
|
||||
} catch (IllegalArgumentException e) {
|
||||
System.out.println("Customer ID must be 5 alphanumeric characters only. Try again.");
|
||||
continue; // retry input if invalid
|
||||
}
|
||||
inputCount++;
|
||||
}
|
||||
|
||||
// Collect and validate SSN
|
||||
while (inputCount == 1) {
|
||||
try {
|
||||
customer.setSSN(DataEntry.inputNumericString("SSN (9 numeric chars): ", 9));
|
||||
} catch (IllegalArgumentException e) {
|
||||
System.out.println("SSN must be exactly 9 digits. Try again.");
|
||||
continue;
|
||||
}
|
||||
inputCount++;
|
||||
}
|
||||
|
||||
// Collect and validate Last Name
|
||||
while (inputCount == 2) {
|
||||
try {
|
||||
customer.setLastName(DataEntry.inputStringWithLimit("Last Name (max 20 chars): ", 20));
|
||||
} catch (IllegalArgumentException e) {
|
||||
System.out.println("Last Name must not contain numbers or special characters. Try again.");
|
||||
continue;
|
||||
}
|
||||
inputCount++;
|
||||
}
|
||||
|
||||
// Collect and validate First Name
|
||||
while (inputCount == 3) {
|
||||
try {
|
||||
customer.setFirstName(DataEntry.inputStringWithLimit("First Name (max 15 chars): ", 15));
|
||||
} catch (IllegalArgumentException e) {
|
||||
System.out.println("First Name must not contain numbers or special characters. Try again.");
|
||||
continue;
|
||||
}
|
||||
inputCount++;
|
||||
}
|
||||
|
||||
// Collect and validate Street Address
|
||||
while (inputCount == 4) {
|
||||
try {
|
||||
customer.setStreet(DataEntry.inputStringWithLimit("Street (max 20 chars): ", 20));
|
||||
} catch (IllegalArgumentException e) {
|
||||
System.out.println("Street must be no more than 20 valid characters. Try again.");
|
||||
continue;
|
||||
}
|
||||
inputCount++;
|
||||
}
|
||||
|
||||
// Collect and validate City
|
||||
while (inputCount == 5) {
|
||||
try {
|
||||
customer.setCity(DataEntry.inputStringWithLimit("City (max 20 chars): ", 20));
|
||||
} catch (IllegalArgumentException e) {
|
||||
System.out.println("City must not contain numbers or special characters. Try again.");
|
||||
continue;
|
||||
}
|
||||
inputCount++;
|
||||
}
|
||||
|
||||
// Collect and validate State
|
||||
while (inputCount == 6) {
|
||||
try {
|
||||
customer.setState(DataEntry.inputStringWithLimit("State (2 chars): ", 2));
|
||||
} catch (IllegalArgumentException e) {
|
||||
System.out.println("State must be 2 letters only. Try again.");
|
||||
continue;
|
||||
}
|
||||
inputCount++;
|
||||
}
|
||||
|
||||
// Collect and validate ZIP code
|
||||
while (inputCount == 7) {
|
||||
try {
|
||||
customer.setZip(DataEntry.inputNumericString("Zip (5 numeric chars): ", 5));
|
||||
} catch (IllegalArgumentException e) {
|
||||
System.out.println("Zip must be exactly 5 digits. Try again.");
|
||||
continue;
|
||||
}
|
||||
inputCount++;
|
||||
}
|
||||
|
||||
// Collect and validate Phone Number
|
||||
while (inputCount == 8) {
|
||||
try {
|
||||
customer.setPhone(DataEntry.inputNumericString("Phone (10 numeric chars): ", 10));
|
||||
} catch (IllegalArgumentException e) {
|
||||
System.out.println("Phone number must be 10 digits only. Try again.");
|
||||
continue;
|
||||
}
|
||||
inputCount++;
|
||||
}
|
||||
|
||||
// Add customer instance to customers ArrayList
|
||||
customers.add(customer);
|
||||
|
||||
// Collect and validate Account Type
|
||||
while (inputCount == 9) {
|
||||
try {
|
||||
String accountType = DataEntry.inputStringWithLimit("Account type ('CHK' or 'SAV' only): ", 3).toUpperCase();
|
||||
if (accountType.equals("CHK")) {
|
||||
account = new CheckingAccount();
|
||||
account.setAccountType("CHK");
|
||||
} else if (accountType.equals("SAV")) {
|
||||
account = new SavingsAccount();
|
||||
account.setAccountType("SAV");
|
||||
} else {
|
||||
throw new IllegalArgumentException("Account type must be 'CHK' or 'SAV'.");
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
System.out.println(e.getMessage());
|
||||
continue;
|
||||
}
|
||||
inputCount++;
|
||||
}
|
||||
|
||||
// Collect and validate Account Number
|
||||
while (inputCount == 10) {
|
||||
try {
|
||||
account.setAccountNumber(DataEntry.inputNumericString("Account Number (5 numeric chars): ", 5));
|
||||
} catch (IllegalArgumentException e) {
|
||||
System.out.println("Account number must be exactly 5 digits. Try again.");
|
||||
continue;
|
||||
}
|
||||
inputCount++;
|
||||
}
|
||||
|
||||
// Collect and validate Service Fee Amount
|
||||
while (inputCount == 11) {
|
||||
try {
|
||||
account.setSvcFee(DataEntry.inputDecimalInRange("Service Fee (0.00 to 10.00): $", 0.00, 10.00));
|
||||
} catch (IllegalArgumentException e) {
|
||||
System.out.println(e.getMessage());
|
||||
continue;
|
||||
}
|
||||
inputCount++;
|
||||
}
|
||||
|
||||
// Collect and validate Interest Rate Amount
|
||||
while (inputCount == 12) {
|
||||
try {
|
||||
account.setInterestRate(DataEntry.inputDecimalInRange("Interest Rate (0.0% to 10.0%): ", 0.0, 10.0));
|
||||
} catch (IllegalArgumentException e) {
|
||||
System.out.println(e.getMessage());
|
||||
continue;
|
||||
}
|
||||
inputCount++;
|
||||
}
|
||||
|
||||
// Collect and validate Overdraft Fee Amount
|
||||
while (inputCount == 13) {
|
||||
try {
|
||||
account.setOverDraftFee(DataEntry.inputDecimal("Overdraft Fee (dollars and cents): $"));
|
||||
} catch (IllegalArgumentException e) {
|
||||
System.out.println(e.getMessage());
|
||||
continue;
|
||||
}
|
||||
inputCount++;
|
||||
}
|
||||
|
||||
// Collect and validate Starting Balance
|
||||
while (inputCount == 14) {
|
||||
try {
|
||||
account.setBalance(DataEntry.inputDecimal("Starting Balance (dollars and cents): $"));
|
||||
} catch (IllegalArgumentException e) {
|
||||
System.out.println(e.getMessage());
|
||||
continue;
|
||||
}
|
||||
inputCount++;
|
||||
}
|
||||
|
||||
// Add account instance to accounts ArrayList
|
||||
accounts.add(account);
|
||||
|
||||
// Ask if more customers should be added
|
||||
String more = DataEntry.inputStringWithLimit("\nAdd another customer? (y/n): ", 1);
|
||||
if (!more.equalsIgnoreCase("y")) {
|
||||
moreCustomers = false;
|
||||
moreCustomers = more.equalsIgnoreCase("y");
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
// Handle transactions
|
||||
boolean addTransactionDetails = true;
|
||||
// Start do-while loop add transaction details to any accounts
|
||||
do {
|
||||
String promptAddTransactions = DataEntry.inputStringWithLimit("Would you like to enter transaction details for an account? (y/n): ", 1).toUpperCase();
|
||||
if (!promptAddTransactions.equals("Y") && !promptAddTransactions.equals("N")) {
|
||||
System.out.println("Please enter 'Y' or 'N' only.");
|
||||
continue; // Prompt again if invalid input
|
||||
} else if (promptAddTransactions.equalsIgnoreCase("N")) {
|
||||
addTransactionDetails = false; // Exit the loop and proceed to report generation
|
||||
} else if (promptAddTransactions.equalsIgnoreCase("Y")) {
|
||||
boolean addTransactionsToAcct = true;
|
||||
// Start do-while loop to add transaction entries to a specified account
|
||||
do {
|
||||
// Prompt for account number
|
||||
String accountNumber = DataEntry.inputNumericString("Enter Account Number (5 digits): ", 5);
|
||||
|
||||
// Find account and corresponding customer
|
||||
Account selectedAccount = null;
|
||||
Customer selectedCustomer = null;
|
||||
|
||||
for (int i = 0; i < accounts.size(); i++) {
|
||||
if (accounts.get(i).getAccountNumber().equals(accountNumber)) {
|
||||
selectedAccount = accounts.get(i);
|
||||
selectedCustomer = customers.get(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("\nCustomer Information:");
|
||||
System.out.println("========================================");
|
||||
for (Customer c : customers) {
|
||||
System.out.println(c);
|
||||
if (selectedAccount == null) {
|
||||
System.out.println("Account not found. Please try again.\n");
|
||||
continue; // Prompt for account number again if not found
|
||||
}
|
||||
|
||||
// Display customer details for verification
|
||||
System.out.println("Customer Information:");
|
||||
System.out.println(selectedCustomer);
|
||||
|
||||
// Add transactions for the selected account
|
||||
boolean newTransaction = true;
|
||||
// Start do-while loop for "newTransactions
|
||||
do {
|
||||
String transaction = null;
|
||||
int transactionStep = 0;
|
||||
String transactionType = "";
|
||||
String transactionDate = "";
|
||||
|
||||
try {
|
||||
while (transactionStep == 0) {
|
||||
transactionType = DataEntry.inputStringWithLimit("\nTransaction Type ('DEP', 'WTH', or 'INT'): ", 3).toUpperCase();
|
||||
if (!transactionType.equals("DEP") && !transactionType.equals("WTH") && !transactionType.equals("INT")) {
|
||||
System.out.println("Invalid transaction type. Please try again.");
|
||||
} else {
|
||||
transactionStep++;
|
||||
}
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
System.out.println("Type must be 'DEP', 'WTH', or 'INT' only. Try again");
|
||||
}
|
||||
|
||||
while (transactionStep == 1) {
|
||||
transactionDate = DataEntry.inputDate("Enter the transaction date (MM/DD/YYYY): ");
|
||||
transactionStep++;
|
||||
}
|
||||
|
||||
while (transactionStep == 2) {
|
||||
double amount = 0;
|
||||
if (!transactionType.equals("INT")) {
|
||||
amount = DataEntry.inputDecimal("Transaction Amount: $");
|
||||
}
|
||||
|
||||
try {
|
||||
if (transactionType.equals("DEP")) {
|
||||
selectedAccount.deposit(amount);
|
||||
transaction = selectedAccount.logTransaction(transactionDate, "DEP", amount);
|
||||
} else if (transactionType.equals("WTH")) {
|
||||
selectedAccount.withdrawal(amount);
|
||||
transaction = selectedAccount.logTransaction(transactionDate, "WTH", amount);
|
||||
} else if (transactionType.equals("INT")) {
|
||||
double interest = selectedAccount.applyAccruedInterest(transactionDate);
|
||||
transaction = selectedAccount.logTransaction(transactionDate, "INT", interest);
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
System.out.println(e.getMessage());
|
||||
continue;
|
||||
}
|
||||
System.out.println(transaction + "\n");
|
||||
|
||||
// Ask if another transaction should be entered for this account
|
||||
String anotherNewTransaction = DataEntry.inputStringWithLimit("Add another transaction for this account? (y/n): ", 1);
|
||||
if (!anotherNewTransaction.equalsIgnoreCase("N") && !anotherNewTransaction.equalsIgnoreCase("Y")) {
|
||||
System.out.println("Please enter 'Y' or 'N' only.");
|
||||
continue;
|
||||
}else if (anotherNewTransaction.equalsIgnoreCase("N")) {
|
||||
newTransaction = false;
|
||||
break;
|
||||
}else if (anotherNewTransaction.equalsIgnoreCase("Y")) {
|
||||
transactionStep = 0;
|
||||
}
|
||||
}
|
||||
}while (newTransaction);
|
||||
|
||||
// Ask if another account's transactions should be entered
|
||||
String otherAcctTransactions = DataEntry.inputStringWithLimit("Enter transactions for another account? (y/n): ", 1);
|
||||
if (!otherAcctTransactions.equalsIgnoreCase("N") && !otherAcctTransactions.equalsIgnoreCase("y")) {
|
||||
System.out.println("Please enter 'Y' or 'N' only.");
|
||||
continue;
|
||||
} else if (otherAcctTransactions.equalsIgnoreCase("N")) {
|
||||
addTransactionsToAcct = false;
|
||||
break;
|
||||
}
|
||||
} while (addTransactionsToAcct);
|
||||
}
|
||||
} while (addTransactionDetails);
|
||||
|
||||
|
||||
|
||||
// Generate final report (this part should be in your existing code)
|
||||
System.out.println("\n------------------------------|Final Report|-------------------------------");
|
||||
for (int i = 0; i < accounts.size(); i++) {
|
||||
Customer customer = customers.get(i);
|
||||
Account account = accounts.get(i);
|
||||
|
||||
System.out.println(customer);
|
||||
|
||||
System.out.println("Account Details:");
|
||||
System.out.println(account);
|
||||
|
||||
System.out.println("Transactions:");
|
||||
for (String transaction : account.getTransactionHistory()) {
|
||||
System.out.println(transaction);
|
||||
}
|
||||
System.out.println("------------------------------|End Report|-------------------------------");
|
||||
}
|
||||
}
|
||||
}
|
42
src/bankAcctApp/CheckingAccount.java
Normal file
42
src/bankAcctApp/CheckingAccount.java
Normal file
@@ -0,0 +1,42 @@
|
||||
/* Phase III */
|
||||
|
||||
package bankAcctApp;
|
||||
|
||||
// Class representing checking accounts
|
||||
public class CheckingAccount extends Account {
|
||||
|
||||
// Overridden method for withdrawals in checking accounts
|
||||
@Override
|
||||
public void withdrawal(double amount) {
|
||||
double newBalance = getBalance() - amount - getSvcFee(); // Deduct amount and service fee
|
||||
if (newBalance < 0) { // Check for overdraft
|
||||
newBalance -= getOverDraftFee(); // Apply overdraft fee if balance is negative
|
||||
}
|
||||
setBalance(newBalance); // Update balance
|
||||
}
|
||||
|
||||
// Overridden method for deposits in checking accounts
|
||||
@Override
|
||||
public void deposit(double amount) {
|
||||
setBalance(getBalance() + amount - getSvcFee()); // Add amount and deduct service fee
|
||||
}
|
||||
|
||||
// Overridden method for applying accrued interest in checking accounts
|
||||
@Override
|
||||
public double applyAccruedInterest(String transactionDate) {
|
||||
double interest = 0.0;
|
||||
if (getBalance() <= 0.0) { // Ensure balance is positive for interest accrual
|
||||
System.out.println("This account has an insufficient balance for interest to apply.");
|
||||
} else {
|
||||
interest = getBalance() * (getInterestRate() / 100); // Calculate interest
|
||||
setBalance(getBalance() + interest); // Add interest to the balance
|
||||
logTransaction(transactionDate, "INT", interest); // Log the interest transaction
|
||||
}
|
||||
return interest;
|
||||
}
|
||||
// Implementation of balance() method from AccountInterface
|
||||
@Override
|
||||
public double balance() {
|
||||
return getBalance(); // Return the current balance
|
||||
}
|
||||
}
|
@@ -1,5 +1,9 @@
|
||||
/* Phase III */
|
||||
|
||||
package bankAcctApp;
|
||||
|
||||
public class Customer {
|
||||
|
||||
private String id;
|
||||
private String ssn;
|
||||
private String lastName;
|
||||
@@ -10,6 +14,7 @@ public class Customer {
|
||||
private String zip;
|
||||
private String phone;
|
||||
|
||||
|
||||
// Getter and Setter for Customer ID info.
|
||||
public String getID() {
|
||||
return id;
|
||||
@@ -18,6 +23,7 @@ public class Customer {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
// Getter and Setter for Customer SSN info.
|
||||
public String getSSN() {
|
||||
return ssn;
|
||||
@@ -26,6 +32,7 @@ public class Customer {
|
||||
this.ssn = ssn;
|
||||
}
|
||||
|
||||
|
||||
// Getter and Setter for Customer Last Name.
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
@@ -34,6 +41,7 @@ public class Customer {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
|
||||
// Getter and Setter for Customer First Name.
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
@@ -42,6 +50,7 @@ public class Customer {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
|
||||
// Getter and Setter for Customer Street Address.
|
||||
public String getStreet() {
|
||||
return street;
|
||||
@@ -50,6 +59,7 @@ public class Customer {
|
||||
this.street = street;
|
||||
}
|
||||
|
||||
|
||||
// Getter and Setter for Customer City.
|
||||
public String getCity() {
|
||||
return city;
|
||||
@@ -67,6 +77,7 @@ public class Customer {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
|
||||
// Getter and Setter for Customer ZIP.
|
||||
public String getZip() {
|
||||
return zip;
|
||||
@@ -75,6 +86,7 @@ public class Customer {
|
||||
this.zip = zip;
|
||||
}
|
||||
|
||||
|
||||
// Getter and Setter for Customer Phone Number.
|
||||
public String getPhone() {
|
||||
return phone;
|
||||
@@ -83,13 +95,17 @@ public class Customer {
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
|
||||
// Override the toString() method that is inherited by default from Java's Object class.
|
||||
// Then use the custom-written toString() method to return Customer Info
|
||||
@Override
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format(
|
||||
"ID: %s, SSN: %s, Name: %s %s, Address: %s, %s, %s %s, Phone: %s",
|
||||
id, ssn, firstName, lastName, street, city, state, zip, phone
|
||||
"---------------------\n" +
|
||||
"ID: Last Name: First Name: SSN: Phone: Street: City: ST: ZIP: \n" +
|
||||
"--- ---------- ----------- ---- ------ ------- ----- --- ---- \n" +
|
||||
"%-7s %-22s %-17s %-11s %-11s %-22s %-17s %-6s %-7s",
|
||||
id, lastName, firstName, ssn, phone, street, city, state, zip
|
||||
);
|
||||
}
|
||||
}
|
@@ -1,3 +1,5 @@
|
||||
/* Phase III */
|
||||
|
||||
package bankAcctApp;
|
||||
|
||||
import java.util.Scanner;
|
||||
@@ -18,11 +20,11 @@ public class DataEntry {
|
||||
do {
|
||||
System.out.print(prompt);
|
||||
input = in.nextLine();
|
||||
if (input == "" || input.length() > maxLength) {
|
||||
if (input.isBlank() || input.length() > maxLength) {
|
||||
System.out.println("Invalid input. Must be non-blank and up to "
|
||||
+ maxLength + " characters.");
|
||||
}
|
||||
} while (input == "" || input.length() > maxLength);
|
||||
} while (input.isBlank() || input.length() > maxLength);
|
||||
return input;
|
||||
}
|
||||
|
||||
@@ -32,10 +34,10 @@ public class DataEntry {
|
||||
do {
|
||||
System.out.print(prompt);
|
||||
input = in.nextLine();
|
||||
if (!input.matches("\\d+")) {
|
||||
System.out.println("Invalid input. Must only be numeric characters.");
|
||||
if (!input.matches("\\d{" + length + "}")) {
|
||||
System.out.println("Invalid input. Must be exactly " + length + " numbers.");
|
||||
}
|
||||
} while (!input.matches("\\d+"));
|
||||
} while (!input.matches("\\d{" + length + "}"));
|
||||
return input;
|
||||
}
|
||||
|
||||
@@ -50,20 +52,23 @@ public class DataEntry {
|
||||
isValid = true;
|
||||
} else {
|
||||
System.out.print("Invalid entry. Try again: ");
|
||||
in.nextLine();
|
||||
in.next();
|
||||
}
|
||||
in.nextLine();
|
||||
} while (!isValid);
|
||||
return input;
|
||||
}
|
||||
|
||||
// Static method to validate Integers within a range.
|
||||
// Static method to validate Integers are within a range.
|
||||
public static int inputIntegerInRange(String prompt, int min, int max) {
|
||||
int input = (min - 1);
|
||||
do {
|
||||
input = inputInteger(prompt);
|
||||
if (input < min || input > max) {
|
||||
System.out.print("Invalid input. Try again: ");
|
||||
in.next();
|
||||
}
|
||||
in.nextLine();
|
||||
} while (input < min || input > max);
|
||||
return input;
|
||||
}
|
||||
@@ -81,11 +86,12 @@ public class DataEntry {
|
||||
System.out.println("Invalid input. Please enter a valid decimal number.");
|
||||
in.next();
|
||||
}
|
||||
in.nextLine();
|
||||
} while (!isValid);
|
||||
return decimalValue;
|
||||
}
|
||||
|
||||
// Static method to validate decimals within a range.
|
||||
// Static method to validate decimals are within a range.
|
||||
public static double inputDecimalInRange(String prompt, double min, double max) {
|
||||
double value;
|
||||
do {
|
||||
@@ -93,6 +99,7 @@ public class DataEntry {
|
||||
if (value < min || value > max) {
|
||||
System.out.println("Invalid input. Must be between "
|
||||
+ min + " and " + max + ".");
|
||||
in.next();
|
||||
}
|
||||
} while (value < min || value > max);
|
||||
return value;
|
||||
@@ -103,14 +110,15 @@ public class DataEntry {
|
||||
Pattern patternDate = Pattern.compile("^(0[1-9]|1[0-2])/(0[1-9]|[12][0-9]|3[01])/(\\d{4})$");
|
||||
String date = "";
|
||||
System.out.print(prompt);
|
||||
do {
|
||||
while (date.isEmpty()) {
|
||||
String input = in.nextLine();
|
||||
if (patternDate.matcher(input).matches()) {
|
||||
return input;
|
||||
date = input;
|
||||
return date;
|
||||
} else {
|
||||
System.out.print("Invalid date. Please try again: ");
|
||||
}
|
||||
} while (date == "");
|
||||
}
|
||||
return date;
|
||||
}
|
||||
}
|
41
src/bankAcctApp/SavingsAccount.java
Normal file
41
src/bankAcctApp/SavingsAccount.java
Normal file
@@ -0,0 +1,41 @@
|
||||
/* Phase III */
|
||||
|
||||
package bankAcctApp;
|
||||
|
||||
// Class representing savings accounts
|
||||
public class SavingsAccount extends Account {
|
||||
|
||||
// Overridden method for withdrawals in savings accounts
|
||||
@Override
|
||||
public void withdrawal(double amount) {
|
||||
if (getBalance() >= amount + getSvcFee()) { // Ensure sufficient balance
|
||||
setBalance(getBalance() - amount - getSvcFee()); // Deduct amount and service fee
|
||||
} else {
|
||||
throw new IllegalArgumentException("Insufficient funds for withdrawal. Savings accounts cannot overdraft.");
|
||||
}
|
||||
}
|
||||
|
||||
// Overridden method for deposits in savings accounts
|
||||
@Override
|
||||
public void deposit(double amount) {
|
||||
setBalance(getBalance() + amount - getSvcFee()); // Add amount and deduct service fee
|
||||
}
|
||||
|
||||
// Overridden method for applying accrued interest in savings accounts
|
||||
@Override
|
||||
public double applyAccruedInterest(String transactionDate) {
|
||||
if (getBalance() <= 0) { // Ensure balance is positive for interest accrual
|
||||
throw new IllegalArgumentException("The account has an insufficient balance for interest to apply.");
|
||||
}
|
||||
double interest = getBalance() * (getInterestRate() / 100); // Calculate interest
|
||||
setBalance(getBalance() + interest); // Add interest to the balance
|
||||
logTransaction(transactionDate, "INT", interest); // Log the interest transaction
|
||||
return interest;
|
||||
}
|
||||
|
||||
// Implementation of balance() method from AccountInterface
|
||||
@Override
|
||||
public double balance() {
|
||||
return getBalance(); // Return the current balance
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user