├── .gitignore
├── .DS_Store
├── src
├── .DS_Store
├── model
│ ├── entities
│ │ ├── Accounts.java
│ │ ├── Transaction.java
│ │ ├── CustomerAccount.java
│ │ └── Customer.java
│ ├── TransactionDAO.java
│ ├── Account2DAO.java
│ ├── AccountDAO.java
│ ├── CustomerAccountDAO.java
│ └── CustomerDAO.java
├── connect
│ └── Connect.java
├── stripe
│ ├── pom.xml
│ └── Server.java
├── controller
│ ├── BankController.java
│ └── CustomerController.java
└── view
│ └── ATM.java
├── gui
├── PayFriendsGUI.java
├── PayFriendsGUIB.java
├── SwingExampleA.java
├── PayFriendsGUIC.java
├── SwingExam.form
└── SwingExam.java
├── .github
└── workflows
│ └── maven-publish.yml
├── README.md
└── LICENSE
/.gitignore:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tofetpuzo/Calluma/HEAD/.DS_Store
--------------------------------------------------------------------------------
/src/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tofetpuzo/Calluma/HEAD/src/.DS_Store
--------------------------------------------------------------------------------
/gui/PayFriendsGUI.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package gui;
7 |
8 | import java.awt.Button;
9 | import java.awt.Frame;
10 |
11 | /**
12 | *
13 | * @author femitemiola
14 | */
15 | public class PayFriendsGUI {
16 | public static void main(String[] args){
17 | Frame f = new Frame();
18 |
19 | Button b = new Button("show");
20 | b.setBounds(130, 100, 100, 50);
21 |
22 | f.add(b);
23 | f.setSize(400, 500);
24 |
25 | f.setLayout(null); //It helps you to lay out your object on the frame
26 | f.setVisible(true);
27 |
28 | }
29 |
30 |
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/src/model/entities/Accounts.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package src.model.entities;
7 |
8 | /**
9 | *
10 | * @author femitemiola
11 | */
12 | public class Accounts {
13 |
14 | private final int accountcode;
15 | private String name;
16 |
17 | public Accounts(int accountcode, String name) {
18 | this.accountcode = accountcode;
19 | this.name = name;
20 | }
21 |
22 | public int getAccountcode() {
23 | return accountcode;
24 | }
25 |
26 | public String getName() {
27 | return name;
28 | }
29 |
30 | public void setName(String name) {
31 | this.name = name;
32 | }
33 |
34 | }
35 |
36 |
--------------------------------------------------------------------------------
/gui/PayFriendsGUIB.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package gui;
7 |
8 | import java.awt.Button;
9 | import java.awt.Frame;
10 |
11 | /**
12 | *
13 | * @author femitemiola
14 | */
15 | public class PayFriendsGUIB {
16 | public PayFriendsGUIB(){
17 | Frame f = new Frame();
18 |
19 | Button b = new Button("show");
20 | b.setBounds(130, 100, 100, 50);
21 |
22 | f.add(b);
23 | f.setSize(400, 500);
24 |
25 | f.setLayout(null); //It helps you to lay out your object on the frame
26 | f.setVisible(true);
27 | }
28 |
29 | public static void main(String[] args){
30 | new PayFriendsGUIB();
31 | }
32 |
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/.github/workflows/maven-publish.yml:
--------------------------------------------------------------------------------
1 | # This workflow will build a package using Maven and then publish it to GitHub packages when a release is created
2 | # For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path
3 |
4 | name: Maven Package
5 |
6 | on:
7 | release:
8 | types: [created]
9 |
10 | jobs:
11 | build:
12 |
13 | runs-on: ubuntu-latest
14 | permissions:
15 | contents: read
16 | packages: write
17 |
18 | steps:
19 | - uses: actions/checkout@v4
20 | - name: Set up JDK 11
21 | uses: actions/setup-java@v3
22 | with:
23 | java-version: '11'
24 | distribution: 'temurin'
25 | server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
26 | settings-path: ${{ github.workspace }} # location for the settings.xml file
27 |
28 | - name: Build with Maven
29 | run: mvn -B package --file pom.xml
30 |
31 | - name: Publish to GitHub Packages Apache Maven
32 | run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml
33 | env:
34 | GITHUB_TOKEN: ${{ github.token }}
35 |
--------------------------------------------------------------------------------
/gui/SwingExampleA.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package gui;
7 |
8 | import java.awt.Button;
9 | import java.util.logging.Level;
10 | import java.util.logging.Logger;
11 | import javax.swing.JFrame;
12 | import javax.swing.UIManager;
13 | import javax.swing.UnsupportedLookAndFeelException;
14 |
15 | /**
16 | *
17 | * @author femitemiola
18 | */
19 | public class SwingExampleA {
20 | public static void main(String[] args){
21 | try {
22 | JFrame f = new JFrame();
23 |
24 | Button b = new Button("show");
25 | b.setBounds(130, 100, 100, 50);
26 | f.add(b);
27 | f.setSize(400, 500);
28 | f.setLayout(null); //It helps you to lay out your object on the frame
29 | f.setVisible(true);
30 | UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel()");
31 | UIManager.setLookAndFeel("javax.swing.plaf.motif.MotifLookAndFeel()");
32 | } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
33 | Logger.getLogger(SwingExampleA.class.getName()).log(Level.SEVERE, null, ex);
34 | }
35 |
36 |
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/gui/PayFriendsGUIC.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package gui;
7 |
8 | import java.awt.Button;
9 | import java.awt.Frame;
10 | import java.util.logging.Level;
11 | import java.util.logging.Logger;
12 |
13 | import javax.swing.UIManager;
14 | import javax.swing.UnsupportedLookAndFeelException;
15 |
16 | /**
17 | *
18 | * @author femitemiola
19 | */
20 | public class PayFriendsGUIC extends Frame {
21 |
22 | public PayFriendsGUIC(String String) throws ClassNotFoundException {
23 | super(String);
24 | try {
25 | Button showButton = new Button("show");
26 | b.setBounds(130, 100, 100, 50);
27 |
28 | add(b);
29 | setSize(400, 500);
30 | setLayout(null); //It helps you to lay out your object on the frame
31 | setVisible(true);
32 | UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel()");
33 | UIManager.setLookAndFeel("javax.swing.plaf.motif.MotifLookAndFeel()");
34 | } catch (InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
35 | Logger.getLogger(PayFriendsGUIC.class.getName()).log(Level.SEVERE, null, ex);
36 | }
37 |
38 | }
39 |
40 | public static void main(String args[]){
41 | try {
42 | PayFriendsGUI payFriends = new PayFriendsGUI("payFriendsGUI");
43 | } catch (ClassNotFoundException ex) {
44 | Logger.getLogger(PayFriendsGUI.class.getName()).log(Level.SEVERE, null, ex);
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/connect/Connect.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package src.connect;
7 |
8 | import java.io.FileInputStream;
9 | import java.io.IOException;
10 | import java.io.InputStream;
11 | import java.sql.Connection;
12 | import java.sql.DriverManager;
13 | /**
14 | *
15 | * @author femitemiola
16 | */
17 | import java.sql.SQLException;
18 | import java.util.Properties;
19 |
20 | public class Connect {
21 |
22 | static String url;
23 | static String user;
24 | static String pass;
25 | static Connection con = null;
26 |
27 | private Connect() {
28 | // private constructor to hide the implicit public one
29 | Properties prop = new Properties();
30 | String env = System.getenv("APP_ENV"); // Use environment variable to determine the environment
31 | String propFileName = "config-" + env + ".properties";
32 |
33 | try (InputStream input = new FileInputStream("/path/to/config/" + propFileName)) {
34 | // Load the properties file
35 | prop.load(input);
36 |
37 | // Get the property values
38 | prop.getProperty("db.url");
39 | prop.getProperty("db.user");
40 | System.getenv("DB_PASSWORD"); // Fetch password from environment variable
41 |
42 | } catch (IOException ex) {
43 | ex.printStackTrace();
44 | }
45 | }
46 |
47 | // connect to database
48 | private static Connection getConnection() throws SQLException {
49 | con = DriverManager.getConnection(url, user, pass);
50 |
51 | return con;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/model/entities/Transaction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package src.model.entities;
7 |
8 | import java.util.Date;
9 |
10 | /**
11 | *
12 | * @author femitemiola
13 | */
14 | public class Transaction {
15 | private int trxnCode;
16 | private String accountNo;
17 | private double amount;
18 | private double workingBalance;
19 | private Date trxnDate;
20 |
21 | public Transaction(int trxnCode, String accountNo, double amount, double workingBalance, Date trxnDate) {
22 | this.trxnCode = trxnCode;
23 | this.accountNo = accountNo;
24 | this.amount = amount;
25 | this.workingBalance = workingBalance;
26 | this.trxnDate = trxnDate;
27 | }
28 |
29 | public int getTrxnCode() {
30 | return trxnCode;
31 | }
32 |
33 | public void setTrxnCode(int trxnCode) {
34 | this.trxnCode = trxnCode;
35 | }
36 |
37 | public String getAccountNo() {
38 | return accountNo;
39 | }
40 |
41 | public void setAccountNo(String accountNo) {
42 | this.accountNo = accountNo;
43 | }
44 |
45 | public double getAmount() {
46 | return amount;
47 | }
48 |
49 | public void setAmount(double amount) {
50 | this.amount = amount;
51 | }
52 |
53 | public double getWorkingBalance() {
54 | return workingBalance;
55 | }
56 |
57 | public void setWorkingBalance(double workingBalance) {
58 | this.workingBalance = workingBalance;
59 | }
60 |
61 | public Date getTrxnDate() {
62 | return trxnDate;
63 | }
64 |
65 | public void setTrxnDate(Date trxnDate) {
66 | this.trxnDate = trxnDate;
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/src/model/entities/CustomerAccount.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package src.model.entities;
7 |
8 | import java.util.Date;
9 |
10 |
11 | /**
12 | *
13 | * @author femitemiola
14 | */
15 | public class CustomerAccount {
16 |
17 | private String AccountNo;
18 | private final int customerCode;
19 | private final int accountCode;
20 | private String Pin;
21 | private double balance;
22 | private final Date dateCreated;
23 | private String status;
24 |
25 | public CustomerAccount(String AccountNo, int customerCode, int accountCode, String Pin, double balance, Date dateCreated, String status) {
26 | this.AccountNo = AccountNo;
27 | this.customerCode = customerCode;
28 | this.accountCode = accountCode;
29 | this.Pin = Pin;
30 | this.balance = balance;
31 | this.dateCreated = dateCreated;
32 | this.status = status;
33 | }
34 |
35 | public String getStatus() {
36 | return status;
37 | }
38 |
39 | public void setStatus(String status) {
40 | this.status = status;
41 | }
42 |
43 | public String getAccountNo() {
44 | return AccountNo;
45 | }
46 |
47 | public void setAccountNo(String AccountNo) {
48 | this.AccountNo = AccountNo;
49 | }
50 |
51 | public int getCustomerCode() {
52 | return customerCode;
53 | }
54 |
55 | public int getAccountCode() {
56 | return accountCode;
57 | }
58 |
59 | public String getPin() {
60 | return Pin;
61 | }
62 |
63 | public void setPin(String Pin) {
64 | this.Pin = Pin;
65 | }
66 |
67 | public double getBalance() {
68 | return balance;
69 | }
70 |
71 | public void setBalance(double balance) {
72 | this.balance = balance;
73 | }
74 |
75 | public Date getDateCreated() {
76 | return dateCreated;
77 | }
78 |
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Calluma
2 |
3 | Calluma is banking application developed in Java. This application aims to provide users with a seamless and intuitive experience for managing their daily expenses and also keep track of their expenses and help save money.
4 |
5 | ## Features
6 |
7 | - **User Authentication:** Secure login and registration system.
8 | - **Track Expenses:** see how much you spend .
9 | - **Subscriptions:** find subscriptions/expenses easily in bank accounts
10 | - **User Profile:** View and edit user profile information.
11 |
12 |
13 | ## Getting Started
14 |
15 | These instructions will help you get a copy of the project up and running on your local machine for development and testing purposes.
16 |
17 | ### Prerequisites
18 |
19 | - Java Development Kit (JDK) 8 or higher
20 |
21 | ### Installation
22 |
23 | 1. **Clone the repository:**
24 |
25 | ```bash
26 | git clone https://github.com/your-username/MyMobileApp.git
27 | ```
28 |
29 | 2. **Build the project:**
30 |
31 | - Click on `Build` > `Rebuild Project` to build the project and download necessary dependencies.
32 |
33 |
34 | 3. **Log in:**
35 |
36 | - Use your registered email and password to log in.
37 |
38 | ## Built With
39 |
40 | - [Java](https://www.java.com) - The programming language used.
41 |
42 | ## Contributing
43 |
44 | 1. Fork the repository.
45 | 2. Create a new branch (`git checkout -b feature-branch`).
46 | 3. Make your changes.
47 | 4. Commit your changes (`git commit -am 'Add new feature'`).
48 | 5. Push to the branch (`git push origin feature-branch`).
49 | 6. Create a new Pull Request.
50 |
51 | ## Authors
52 |
53 | - **Tems** - _Initial work_ - [Tems](https://github.com/your-username)
54 |
55 | See also the list of [contributors](https://github.com/your-username/MyMobileApp/contributors) who participated in this project.
56 |
57 | ## License
58 |
59 | This project is licensed under the MIT License - see the [LICENSE.me](LICENSE.md) file for details.
60 |
61 | ## Acknowledgments
62 |
63 | - Hat tip to anyone whose code was used
64 | - Inspiration
65 | - etc
66 |
67 | ---
68 |
--------------------------------------------------------------------------------
/src/stripe/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 |
6 | com.stripe.sample
7 | single-subscription-checkout
8 | 1.0.0-SNAPSHOT
9 |
10 |
11 |
12 |
13 | org.slf4j
14 | slf4j-simple
15 | 2.0.6
16 |
17 |
18 | com.sparkjava
19 | spark-core
20 | 2.9.4
21 |
22 |
23 | com.google.code.gson
24 | gson
25 | 2.10.1
26 |
27 |
28 | com.stripe
29 | stripe-java
30 | 25.13.0
31 |
32 |
33 | io.github.cdimascio
34 | java-dotenv
35 | 5.2.2
36 |
37 |
38 |
39 | sample
40 |
41 |
42 | org.apache.maven.plugins
43 | maven-compiler-plugin
44 | 3.11.0
45 |
46 | 1.8
47 | 1.8
48 |
49 |
50 |
51 | maven-assembly-plugin
52 |
53 |
54 | package
55 |
56 | single
57 |
58 |
59 |
60 |
61 |
62 |
63 | jar-with-dependencies
64 |
65 |
66 |
67 | Server
68 |
69 |
70 |
71 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/src/model/TransactionDAO.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package src.model;
7 |
8 | /**
9 | *
10 | * @author femitemiola
11 | */
12 | import java.sql.Connection;
13 | import java.sql.ResultSet;
14 | import java.sql.SQLException;
15 | import java.util.logging.Level;
16 | import java.util.logging.Logger;
17 | import src.connect.Connect;
18 | import java.sql.Statement;
19 | import src.model.entities.Transaction;
20 |
21 | public class TransactionDAO {
22 |
23 | static Connection con = null;
24 |
25 |
26 | public static ResultSet getAllTransactions() {
27 | try {
28 | con = Connect.getConnection();
29 |
30 | if (con != null) {
31 | Statement smt = con.createStatement();
32 | String query = "SELECT * FROM transactions";
33 | ResultSet rs = smt.executeQuery(query);
34 | while (rs.next()) {
35 | return rs;
36 | }
37 |
38 | }
39 | } catch (SQLException ex) {
40 | Logger.getLogger(TransactionDAO.class.getName()).log(Level.SEVERE, null, ex);
41 | }
42 | return null;
43 | }
44 |
45 | public static boolean insertTransaction(Transaction transaction) {
46 | try {
47 | con = Connect.getConnection();
48 | int status = 0;
49 | if (con != null) {
50 | Statement smt = con.createStatement();
51 | String query = "INSERT into transactions(trxnCode, accountNo, amount, workingBalance, trxnDate) "
52 | + "values(NULL,'" + transaction.getAccountNo() + "', " + transaction.getAmount()
53 | + ", " + transaction.getWorkingBalance() + ", NULL)";
54 | status = smt.executeUpdate(query);
55 | if (status > 0) {
56 | return true;
57 | }
58 |
59 | }
60 | } catch (SQLException ex) {
61 | Logger.getLogger(TransactionDAO.class.getName()).log(Level.SEVERE, null, ex);
62 | }
63 | return false;
64 | }
65 |
66 | public static ResultSet getTransactionById(int trxn_id) {
67 | try {
68 | con = Connect.getConnection();
69 |
70 | if (con != null) {
71 | Statement smt = con.createStatement();
72 | String query = "SELECT * FROM transactions where trxnCode= " + trxn_id;
73 | ResultSet rs = smt.executeQuery(query);
74 | while (rs.next()) {
75 | return rs;
76 | }
77 |
78 | }
79 | } catch (SQLException ex) {
80 | Logger.getLogger(TransactionDAO.class.getName()).log(Level.SEVERE, null, ex);
81 | }
82 | return null;
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/src/model/Account2DAO.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package src.model;
7 |
8 | import src.model.entities.Accounts;
9 | import java.sql.Statement;
10 | import java.sql.SQLException;
11 | import java.sql.Connection;
12 | import java.sql.ResultSet;
13 | import java.util.logging.Level;
14 | import java.util.logging.Logger;
15 | import src.connect.Connect;
16 |
17 | /**
18 | *
19 | * @author femitemiola
20 | */
21 | public class Account2DAO {
22 |
23 | static Connection con = null;
24 |
25 | private Account2DAO() {
26 | // private constructor to hide the implicit public one
27 | }
28 |
29 | public static ResultSet getAllAccounts() {
30 |
31 | try {
32 | con = Connect.getConnection();
33 | if (con != null) {
34 | Statement smt = con.createStatement();
35 | String query = "SELECT * FROM Accounts";
36 | ResultSet rs = smt.executeQuery(query);
37 | while (rs.next()) {
38 | return rs;
39 | }
40 | }
41 | } catch (SQLException ex) {
42 | Logger.getLogger(Account2DAO.class.getName()).log(Level.SEVERE, null, ex);
43 | }
44 | return null;
45 |
46 | }
47 |
48 | public static boolean insertAccountsById(Accounts account) {
49 | int status = 0;
50 | try {
51 | con = Connect.getConnection();
52 | if (con != null) {
53 | Statement smt = con.createStatement();
54 | String query = "INSERT INTO Accounts (name) values= '" + account.getName() + "'";
55 | status = smt.executeUpdate(query);
56 | if (status > 0) {
57 | return true;
58 | }
59 | }
60 |
61 | } catch (SQLException ex) {
62 | Logger.getLogger(Account2DAO.class.getName()).log(Level.SEVERE, null, ex);
63 | }
64 | return false;
65 | }
66 |
67 | public static boolean deleteAccountById(int account_id) {
68 | int status = 0;
69 |
70 | try {
71 | con = Connect.getConnection();
72 | if (con != null) {
73 | Statement smt = con.createStatement();
74 | String query = "delete from Accounts where accountcode='" + account_id + "'";
75 | status = smt.executeUpdate(query);
76 | if (status > 0) {
77 | return true;
78 | }
79 | }
80 |
81 | } catch (SQLException ex) {
82 | Logger.getLogger(Account2DAO.class.getName()).log(Level.SEVERE, null, ex);
83 | }
84 | return false;
85 | }
86 |
87 | public static boolean updateAccountbyId(Accounts account) {
88 | int status = 0;
89 |
90 | try {
91 | con = Connect.getConnection();
92 | if (con != null) {
93 | Statement smt = con.createStatement();
94 | String query = "update Accounts set name '" + account.getName() + "'";
95 | status = smt.executeUpdate(query);
96 | if (status > 0) {
97 | return true;
98 | }
99 | }
100 |
101 | } catch (SQLException ex) {
102 | Logger.getLogger(Account2DAO.class.getName()).log(Level.SEVERE, null, ex);
103 | }
104 | return false;
105 |
106 | }
107 |
108 | }
109 |
--------------------------------------------------------------------------------
/src/controller/BankController.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package src.controller;
7 |
8 | import java.util.ArrayList;
9 | import src.model.AccountDAO;
10 | import src.model.CustomerAccountDAO;
11 | import src.model.entities.Accounts;
12 | import java.sql.ResultSet;
13 | import java.sql.SQLException;
14 | import java.util.Date;
15 | import java.util.logging.Level;
16 | import java.util.logging.Logger;
17 | import src.model.CustomerDAO;
18 | import src.model.entities.Customer;
19 | import src.model.entities.CustomerAccount;
20 |
21 | /**
22 | *
23 | * @author femitemiola
24 | */
25 | public class BankController {
26 |
27 | private static final ArrayList accountType = new ArrayList<>();
28 |
29 | public static boolean deleteCustomerById(String account_No) {
30 | return CustomerAccountDAO.deleteCustomerAccount(account_No);
31 | }
32 |
33 | public double checkBalance(String accountNo) {
34 | ResultSet rs = CustomerAccountDAO.getCustomerAccountbyAccountNo(accountNo);
35 | if (rs != null) {
36 | try {
37 | while (rs.next()) {
38 | return rs.getDouble("balance");
39 | }
40 | } catch (SQLException ex) {
41 | Logger.getLogger(BankController.class.getName()).log(Level.SEVERE, null, ex);
42 | }
43 | }
44 | return 0;
45 |
46 | }
47 |
48 | public boolean authenticate(String urs, String pwrsds) {
49 | return CustomerDAO.authenticate(urs, pwrsds);
50 | }
51 |
52 | public boolean addCustomerAccount(CustomerAccount customeraccount){
53 | return CustomerAccountDAO.insertCustomerAccount(customeraccount);
54 | }
55 |
56 | public boolean deleteCustomerAccount(String accountNo){
57 | return CustomerAccountDAO.deleteCustomerAccount(accountNo);
58 | }
59 |
60 | public ResultSet getallCustomerAccount(){
61 | return CustomerAccountDAO.getAllCustomersAccounts();
62 | }
63 |
64 | public List getAllAccounts() {
65 | ResultSet rs = AccountDAO.getAllAccounts();
66 | try {
67 | while (rs.next()) {
68 | accountType.add(new Accounts(rs.getInt(1), rs.getString(2)));
69 |
70 | }
71 | } catch (SQLException ex) {
72 | Logger.getLogger(BankController.class.getName()).log(Level.SEVERE, null, ex);
73 | }
74 | return accountType;
75 | }
76 |
77 | // get a particular customer
78 | public Customer getCustomersbyData(String firstName, String middleName, String lastName, char gender, Date dob) {
79 | Customer cust = null;
80 | try {
81 |
82 | ResultSet rs = CustomerDAO.getCustomerbyData(firstName, middleName, lastName, gender, dob);
83 | while (rs.next()) {
84 | cust = new Customer(rs.getInt(1), rs.getString(2),
85 | rs.getString(3), rs.getString(4),
86 | rs.getString(5), rs.getString(6),
87 | rs.getString(7), rs.getString(8),
88 | rs.getString(9), rs.getString(10),
89 | rs.getString(11), rs.getDate(12),
90 | rs.getString(13), rs.getString(14).charAt(0));
91 | }
92 |
93 | } catch (SQLException ex) {
94 | Logger.getLogger(BankController.class.getName()).log(Level.SEVERE, null, ex);
95 | }
96 | return cust;
97 | }
98 |
99 | }
100 |
--------------------------------------------------------------------------------
/src/model/AccountDAO.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package src.model;
7 |
8 | /**
9 | *
10 | * @author femitemiola
11 | */
12 | import java.sql.Statement;
13 | import java.sql.SQLException;
14 | import java.sql.Connection;
15 | import java.sql.ResultSet;
16 | import java.util.logging.Level;
17 | import java.util.logging.Logger;
18 | import src.connect.Connect;
19 | import src.model.entities.Accounts;
20 |
21 | public class AccountDAO {
22 |
23 | static Connection con = null;
24 |
25 | private AccountDAO() {
26 | // private constructor to hide the implicit public one
27 | }
28 |
29 | public static ResultSet getAllAccounts() {
30 |
31 | try {
32 | //con accesses all the information from mysql
33 | con = Connect.getConnection();
34 | if (con != null) {
35 | Statement smt = con.createStatement();
36 | String query = "SELECT accountName, accountAddress, accountID FROM accounts";
37 | ResultSet rs = smt.executeQuery(query);
38 | while (rs.next()) {
39 | return rs;
40 | }
41 | }
42 |
43 | } catch (SQLException ex) {
44 | Logger.getLogger(AccountDAO.class.getName()).log(Level.SEVERE, null, ex);
45 | }
46 | return null;
47 |
48 | }
49 |
50 | public static boolean DeleteAccountbyId(int account_id) {
51 | int status = 0;
52 | try {
53 |
54 | con = Connect.getConnection();
55 | if (con != null) {
56 | Statement smt = con.createStatement();
57 | String query = "delete FROM accounts where accountcode = " + account_id;
58 | status = smt.executeUpdate(query);
59 | if (status > 0) {
60 | return true;
61 | }
62 | }
63 |
64 | } catch (SQLException ex) {
65 | Logger.getLogger(AccountDAO.class.getName()).log(Level.SEVERE, null, ex);
66 | }
67 | return false;
68 |
69 | }
70 |
71 | public static boolean updateAccountbyId(Accounts account) {
72 | int status = 0;
73 | try {
74 |
75 | con = Connect.getConnection();
76 | if (con != null) {
77 | Statement smt = con.createStatement();
78 | String query = "upate Accounts set name= " + account.getName();
79 | status = smt.executeUpdate(query);
80 | if (status > 0) {
81 | return true;
82 | }
83 | }
84 |
85 | } catch (SQLException ex) {
86 | Logger.getLogger(AccountDAO.class.getName()).log(Level.SEVERE, null, ex);
87 | }
88 | return false;
89 |
90 | }
91 |
92 | public static boolean insertAccountbyId(Accounts account) {
93 | int status = 0;
94 | try {
95 |
96 | con = Connect.getConnection();
97 | if (con != null) {
98 | Statement smt = con.createStatement();
99 | String query = "insert into accounts (name) values ('" + account.getName() + "') ";
100 | status = smt.executeUpdate(query);
101 | if (status > 0) {
102 | return true;
103 | }
104 | }
105 |
106 | } catch (SQLException ex) {
107 | Logger.getLogger(AccountDAO.class.getName()).log(Level.SEVERE, null, ex);
108 | }
109 | return false;
110 |
111 | }
112 |
113 | }
114 |
--------------------------------------------------------------------------------
/src/model/entities/Customer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package src.model.entities;
7 |
8 | import java.util.Date;
9 |
10 | /**
11 | *
12 | * @author femitemiola
13 | */
14 | public class Customer {
15 | private final int customercode;
16 | private String firstName;
17 | private String middleName;
18 | private String lastName;
19 | private String address;
20 | private String city;
21 | private String state;
22 | private String Country;
23 | private String c_code;
24 | private String mobile;
25 | private String email;
26 | private Date dob;
27 | private String nok;
28 | private final char gender;
29 |
30 | public Customer(CustomerInfo customerInfo) {
31 | this.customercode = customerInfo.getCustomercode();
32 | this.firstName = customerInfo.getFirstName();
33 | this.middleName = customerInfo.getMiddleName();
34 | this.lastName = customerInfo.getLastName();
35 | this.address = customerInfo.getAddress();
36 | this.city = customerInfo.getCity();
37 | this.state = customerInfo.getState();
38 | this.Country = customerInfo.getCountry();
39 | this.c_code = customerInfo.getC_code();
40 | this.mobile = customerInfo.getMobile();
41 | this.email = customerInfo.getEmail();
42 | this.dob = customerInfo.getDob();
43 | this.nok = customerInfo.getNok();
44 | this.gender = customerInfo.getGender();
45 | }
46 |
47 | public char getGender() {
48 | return gender;
49 | }
50 |
51 | public int getCustomercode() {
52 | return customercode;
53 | }
54 |
55 | public String getFirstName() {
56 | return firstName;
57 | }
58 |
59 | public void setFirstName(String firstName) {
60 | this.firstName = firstName;
61 | }
62 |
63 | public String getMiddleName() {
64 | return middleName;
65 | }
66 |
67 | public void setMiddleName(String middleName) {
68 | this.middleName = middleName;
69 | }
70 |
71 | public String getLastName() {
72 | return lastName;
73 | }
74 |
75 | public void setLastName(String lastName) {
76 | this.lastName = lastName;
77 | }
78 |
79 | public String getAddress() {
80 | return address;
81 | }
82 |
83 | public void setAddress(String address) {
84 | this.address = address;
85 | }
86 |
87 | public String getCity() {
88 | return city;
89 | }
90 |
91 | public void setCity(String city) {
92 | this.city = city;
93 | }
94 |
95 | public String getState() {
96 | return state;
97 | }
98 |
99 | public void setState(String state) {
100 | this.state = state;
101 | }
102 |
103 | public String getCountry() {
104 | return Country;
105 | }
106 |
107 | public void setCountry(String Country) {
108 | this.Country = Country;
109 | }
110 |
111 | public String getCountryCode() {
112 | return c_code;
113 | }
114 |
115 | public String getMobile() {
116 | return mobile;
117 | }
118 |
119 | public void setMobile(String mobile) {
120 | this.mobile = mobile;
121 | }
122 |
123 | public String getEmail() {
124 | return email;
125 | }
126 |
127 | public void setEmail(String email) {
128 | this.email = email;
129 | }
130 |
131 | public Date getDob() {
132 | return dob;
133 | }
134 |
135 | public Date setdob(Date dob) {
136 | this.dob = dob;
137 | return null;
138 | }
139 |
140 | public String getNok() {
141 | return nok;
142 | }
143 |
144 | public void setNok(String nok) {
145 | this.nok = nok;
146 | }
147 |
148 | }
149 |
--------------------------------------------------------------------------------
/src/stripe/Server.java:
--------------------------------------------------------------------------------
1 | package stripe;
2 |
3 | import java.nio.file.Paths;
4 |
5 | import java.util.HashMap;
6 | import java.util.Map;
7 |
8 | import static spark.Spark.get;
9 | import static spark.Spark.post;
10 | import static spark.Spark.port;
11 | import static spark.Spark.staticFiles;
12 |
13 | import com.google.gson.Gson;
14 | import com.google.gson.annotations.SerializedName;
15 |
16 | import com.stripe.Stripe;
17 | import com.stripe.model.Event;
18 | import com.stripe.exception.*;
19 | import com.stripe.net.Webhook;
20 | import com.stripe.model.checkout.Session;
21 | import com.stripe.param.checkout.SessionCreateParams;
22 |
23 | import io.github.cdimascio.dotenv.Dotenv;
24 |
25 | public class Server {
26 | private static Gson gson = new Gson();
27 |
28 | public static void main(String[] args) {
29 | dotenv = Dotenv.configure().directory(Paths.get(Paths.get("").toAbsolutePath().toString(), "config").toString()).load();
30 | port(dotenv.get("PORT", Integer.class));
31 | dotenv.get("SUCCESS_STATUS_CODE", Integer.class);
32 |
33 | Dotenv dotenv = Dotenv.load();
34 |
35 | Stripe.apiKey = dotenv.get("STRIPE_SECRET_KEY");
36 | // For sample support and debugging, not required for production:
37 | Stripe.setAppInfo(
38 | "stripe-samples/checkout-single-subscription",
39 | "0.0.2",
40 | "https://github.com/stripe-samples/checkout-single-subscription"
41 | );
42 |
43 |
44 | staticFiles.externalLocation(
45 | Paths.get(Paths.get("").toAbsolutePath().toString(), dotenv.get("STATIC_DIR")).normalize().toString());
46 |
47 | get("/config", (request, response) -> {
48 | response.type("application/json");
49 |
50 | Map responseData = new HashMap<>();
51 | responseData.put("publishableKey", dotenv.get("STRIPE_PUBLISHABLE_KEY"));
52 | responseData.put("basicPrice", dotenv.get("BASIC_PRICE_ID"));
53 | responseData.put("proPrice", dotenv.get("PRO_PRICE_ID"));
54 | return gson.toJson(responseData);
55 | });
56 |
57 | // Fetch the Checkout Session to display the JSON result on the success page
58 | get("/checkout-session", (request, response) -> {
59 | response.type("application/json");
60 |
61 | String sessionId = request.queryParams("sessionId");
62 | Session session = Session.retrieve(sessionId);
63 |
64 | return gson.toJson(session);
65 | });
66 |
67 | post("/create-checkout-session", (request, response) -> {
68 | String domainUrl = dotenv.get("DOMAIN");
69 |
70 | // Create new Checkout Session for the order
71 | // Other optional params include:
72 | // [billing_address_collection] - to display billing address details on the page
73 | // [customer] - if you have an existing Stripe Customer ID
74 | // [payment_intent_data] - lets capture the payment later
75 | // [customer_email] - lets you prefill the email input in the form
76 | // [automatic_tax] - to automatically calculate sales tax, VAT and GST in the checkout page
77 | // For full details see https://stripe.com/docs/api/checkout/sessions/create
78 |
79 | // ?session_id={CHECKOUT_SESSION_ID} means the redirect will have the session ID
80 | // set as a query param
81 | SessionCreateParams params = new SessionCreateParams.Builder()
82 | .setSuccessUrl(domainUrl + "/success.html?session_id={CHECKOUT_SESSION_ID}")
83 | .setCancelUrl(domainUrl + "/canceled.html")
84 | .setMode(SessionCreateParams.Mode.SUBSCRIPTION)
85 | .addLineItem(new SessionCreateParams.LineItem.Builder()
86 | .setQuantity(1L)
87 | .setPrice(request.queryParams("priceId"))
88 | .build()
89 | )
90 | // .setAutomaticTax(SessionCreateParams.AutomaticTax.builder().setEnabled(true).build()).
91 | .build();
92 |
93 | try {
94 | Session session = Session.create(params);
95 | response.redirect(session.getUrl(), 303);
96 | return "";
97 | } catch(Exception e) {
98 | Map messageData = new HashMap<>();
99 | messageData.put("message", e.getMessage());
100 | Map responseData = new HashMap<>();
101 | responseData.put("error", messageData);
102 | response.status(this.code);
103 | return gson.toJson(responseData);
104 | }
105 | });
106 | }
--------------------------------------------------------------------------------
/src/model/CustomerAccountDAO.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package src.model;
7 | import java.sql.Statement;
8 | import java.sql.SQLException;
9 | import java.sql.Connection;
10 | import java.sql.ResultSet;
11 | import java.util.logging.Level;
12 | import java.util.logging.Logger;
13 | import src.connect.Connect;
14 | import src.model.entities.CustomerAccount;
15 |
16 | /**
17 | *
18 | * @author femitemiola
19 | */
20 |
21 | public class CustomerAccountDAO {
22 |
23 | static CustomerAccount customeraccount = null;
24 |
25 | static Connection con = null;
26 | // Print out all the whole customers have
27 |
28 | public static ResultSet getAllCustomersAccounts() {
29 | try {
30 | con = Connect.getConnection();
31 | if (con != null) {
32 | Statement smt = con.createStatement();
33 | String query = "SELECT ca.accountNo as \"Account NO\", ca.customercode, ca.accountcode, ca.pin,"
34 | + " ca.balance, ca.dateCreated as \" Opening date\" as a.name as \"Account Type\", "
35 | + "concat(c.firstname, '', c.lastname) as Fullname"
36 | + "from customeraccount "
37 | + "ca join accounts a ON ca.customercode = a.accountcode ca join customer c ON ca.customercode = c.customercode ";
38 | return smt.executeQuery(query);
39 |
40 | }
41 |
42 | } catch (SQLException ex) {
43 | Logger.getLogger(CustomerAccountDAO.class.getName()).log(Level.SEVERE, null, ex);
44 | }
45 | return null;
46 |
47 | }
48 |
49 | public static ResultSet getCustomerAccountbyAccountNo(String account_No) {
50 |
51 | try {
52 | con = Connect.getConnection();
53 | if (con != null) {
54 | Statement smt = con.createStatement();
55 | String query = "SELECT ca.accountNo as \"Account NO\", ca.customercode, ca.accountcode, ca.pin,"
56 | + " ca.balance, ca.dateCreated as \" Opening date\" as a.name as \"Account Type\", "
57 | + "concat(c.firstname, '', c.lastname) as Fullname"
58 | + "from customeraccount "
59 | + "ca join accounts a ON ca.customercode = a.accountcode ca join customer c ON ca.customercode = c.customercode "
60 | + "where accountNo= '" + account_No + "'";
61 | return smt.executeQuery(query);
62 | }
63 |
64 | } catch (SQLException ex) {
65 | Logger.getLogger(CustomerAccountDAO.class.getName()).log(Level.SEVERE, null, ex);
66 | }
67 | return null;
68 |
69 | }
70 |
71 | public static boolean updateCustomerAccount(CustomerAccount customeraccount) {
72 |
73 |
74 | int status = 0;
75 | try {
76 | con = Connect.getConnection();
77 | if (con != null) {
78 | Statement smt = con.createStatement();
79 | String query = "update customeraccount set pin = '" + customeraccount.getPin() + "', " + "balance = " + "', '" + customeraccount.getBalance()
80 | + "', " + " status = '" + customeraccount.getStatus() + "', " + " where accountNo = " + "'" + customeraccount.getAccountNo() + "'";
81 | status = smt.executeUpdate(query);
82 | if (status > 0) {
83 | return true;
84 | }
85 |
86 | }
87 | } catch (SQLException ex) {
88 | Logger.getLogger(CustomerAccountDAO.class.getName()).log(Level.SEVERE, null, ex);
89 | }
90 | return false;
91 |
92 | }
93 |
94 | public static boolean insertCustomerAccount(CustomerAccount customeraccount) {
95 | int status = 0;
96 | try {
97 | //String AccountNo, int customerCode, int accountCode, String Pin, double balance, Date dateCreated, String status
98 | con = Connect.getConnection();
99 | if (con != null) {
100 | Statement smt = con.createStatement();
101 | String query = "INSERT into customeraccount VALUES(accountNo, customerCode, accountCode, pin, balance, dateCreated, status ) "
102 | + "values('" + customeraccount.getAccountNo() + "' ," + customeraccount.getCustomerCode() + " ,'"
103 | + customeraccount.getPin() + "'," + customeraccount.getBalance() + ", '" + ", NULL ," + "'Active')";
104 | status = smt.executeUpdate(query);
105 | if (status > 0) {
106 | return true;
107 | }
108 |
109 | }
110 |
111 | } catch (SQLException ex) {
112 | Logger.getLogger(CustomerAccountDAO.class.getName()).log(Level.SEVERE, null, ex);
113 | }
114 | return false;
115 |
116 | }
117 |
118 | public static boolean deleteCustomerAccount(String account_No) {
119 | int status = 0;
120 | try {
121 | con = Connect.getConnection();
122 | if (con != null) {
123 | Statement smt = con.createStatement();
124 | String query = "DELETE from customeraccount where accountNo= '" + account_No + "'";
125 | status = smt.executeUpdate(query);
126 | if (status > 0){
127 | return true;
128 | }
129 | }
130 | } catch (SQLException ex) {
131 | Logger.getLogger(CustomerAccountDAO.class.getName()).log(Level.SEVERE, null, ex);
132 | }
133 | return false;
134 | }
135 |
136 |
137 | }
138 |
--------------------------------------------------------------------------------
/src/controller/CustomerController.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package src.controller;
7 |
8 | import src.model.entities.CustomerAccount;
9 | import src.model.CustomerAccountDAO;
10 | import java.sql.ResultSet;
11 | import java.sql.SQLException;
12 | import java.util.logging.Level;
13 | import java.util.logging.Logger;
14 | import src.model.CustomerDAO;
15 | import src.model.TransactionDAO;
16 | import src.model.entities.Customer;
17 | import src.model.entities.Transaction;
18 |
19 | /**
20 | *
21 | * @author femitemiola
22 | */
23 | public class CustomerController {
24 |
25 | private static CustomerAccount customeraccount = null;
26 |
27 | public double checkBalance() {
28 | return CustomerController.customeraccount.getBalance();
29 | }
30 |
31 | public double deposit(double amount) {
32 |
33 | synchronized (this) {
34 | double balance = customeraccount.getBalance() + amount;
35 | customeraccount.setBalance(balance);
36 | CustomerAccountDAO.updateCustomerAccount(customeraccount);
37 | TransactionDAO.insertTransaction(new Transaction(-1, customeraccount.getAccountNo(), amount, customeraccount.getBalance(), null));
38 | return checkBalance();
39 | }
40 | }
41 |
42 | public double withdraw(double amount) {
43 |
44 | synchronized (this) {
45 | if (customeraccount.getBalance() >= amount) {
46 | double newAmount = customeraccount.getBalance() - amount;
47 | customeraccount.setBalance(newAmount);
48 | CustomerAccountDAO.updateCustomerAccount(customeraccount);
49 | TransactionDAO.insertTransaction(new Transaction(-1, customeraccount.getAccountNo(), amount, customeraccount.getBalance(), null));
50 | }
51 | }
52 | return this.checkBalance();
53 | }
54 |
55 | public CustomerAccount getCustomerAccount(String accountNo) {
56 | ResultSet rs = CustomerAccountDAO.getCustomerAccountbyAccountNo(accountNo);
57 | if (accountNo != null) {
58 | try {
59 | while (rs.next()) {
60 | return new CustomerAccount(rs.getString(1), rs.getInt(2),
61 | rs.getInt(3), rs.getString(3),
62 | rs.getDouble(5), rs.getDate(6), rs.getString(7));
63 | }
64 | } catch (SQLException ex) {
65 | Logger.getLogger(CustomerController.class.getName()).log(Level.SEVERE, null, ex);
66 | }
67 | }
68 |
69 | return null;
70 |
71 | }
72 | public double transferAmount(String accountTo, double amount){
73 | CustomerAccount account = getCustomerAccount(accountTo);
74 | if(account != null){
75 | if(customeraccount.getBalance() >= amount){
76 | customeraccount.setBalance(customeraccount.getBalance() - amount);
77 | account.setBalance(account.getBalance() + amount);
78 | CustomerAccountDAO.updateCustomerAccount(customeraccount);
79 | CustomerAccountDAO.updateCustomerAccount(account);
80 | TransactionDAO.insertTransaction(new Transaction(-1, customeraccount.getAccountNo(), amount * -1, customeraccount.getBalance(), null));
81 | TransactionDAO.insertTransaction(new Transaction(-1, account.getAccountNo(), amount * -1, customeraccount.getBalance(), null));
82 | }
83 | }
84 | return this.checkBalance();
85 |
86 |
87 | }
88 | public boolean authenticateCustomer(String accountNo, String Pin) {
89 | customeraccount = getCustomerAccount(accountNo);
90 | if (customeraccount != null) {
91 | if (Pin != null) {
92 | return customeraccount.getPin().equals(Pin);
93 | }
94 |
95 | }
96 | return false;
97 |
98 | }
99 |
100 | //This is when we have created the customeraccount but we want to normal fill in the details
101 | private Customer getCustomer() {
102 | if (customeraccount != null) {
103 |
104 | try {
105 |
106 | ResultSet rs = CustomerDAO.getCustomerById(customeraccount.getCustomerCode());
107 | while (rs.next()) {
108 | return new Customer(rs.getInt(1), rs.getString(2),
109 | rs.getString(3), rs.getString(4),
110 | rs.getString(5), rs.getString(6),
111 | rs.getString(7), rs.getString(8),
112 | rs.getString(9), rs.getString(10),
113 | rs.getString(11), rs.getDate(12),
114 | rs.getString(13), rs.getString(14).charAt(0));
115 | }
116 |
117 | } catch (SQLException ex) {
118 | Logger.getLogger(BankController.class.getName()).log(Level.SEVERE, null, ex);
119 | }
120 | return null;
121 | }
122 | return null;
123 |
124 | }
125 |
126 | public boolean updateCustomerPin(String oldValue, String newPin) {
127 | if (customeraccount != null) {
128 | if (customeraccount.getPin().equals(oldValue)) {
129 | customeraccount.setPin(newPin);
130 | CustomerAccountDAO.updateCustomerAccount(customeraccount);
131 | return true;
132 | }
133 |
134 | }
135 | return false;
136 | }
137 |
138 | public boolean updateCustomerlastName(String newValue) {
139 | Customer cust = getCustomer();
140 | if (customeraccount != null) {
141 | cust.setLastName(newValue);
142 | cust.getLastName();
143 | CustomerDAO.updateCustomer(cust);
144 | return true;
145 | }
146 | return false;
147 | }
148 |
149 | public boolean updateBalance(double newBalance) {
150 | if (customeraccount != null) {
151 | customeraccount.setBalance(newBalance);
152 | CustomerAccountDAO.updateCustomerAccount(customeraccount);
153 | return true;
154 | }
155 | return false;
156 | }
157 |
158 | public boolean updateAddress(String newValue) {
159 | Customer cust = getCustomer();
160 | if (customeraccount != null) {
161 | String[] values = newValue.split(":");
162 | cust.setAddress(values[0]);
163 | cust.setCity(values[1]);
164 | cust.setState(values[2]);
165 | CustomerDAO.updateCustomer(cust);
166 | return true;
167 | }
168 | return false;
169 | }
170 |
171 | public boolean insertCustomer(Customer customer) {
172 | return CustomerDAO.insertCustomer(customer);
173 | }
174 |
175 | }
176 |
--------------------------------------------------------------------------------
/src/model/CustomerDAO.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package src.model;
7 |
8 | /**
9 | *
10 | * @author femitemiola
11 | */
12 | import java.sql.Statement;
13 | import java.sql.SQLException;
14 | import java.sql.Connection;
15 | import java.sql.ResultSet;
16 | import java.util.Date;
17 | import java.util.logging.Level;
18 | import java.util.logging.Logger;
19 | import src.connect.Connect;
20 | import src.model.entities.Customer;
21 |
22 | public class CustomerDAO {
23 |
24 | static Customer customer = null;
25 | static Connection con = null;
26 |
27 | public static ResultSet getAllCustomer() {
28 | try {
29 | con = Connect.getConnection();
30 | if (con != null) {
31 | String query = "SELECT * FROM customers ";
32 | ResultSet rs = createCustomerStatement().executeQuery(query);
33 | while (rs.next()) {
34 | return rs;
35 | }
36 | }
37 | return null;
38 | } catch (SQLException ex) {
39 | Logger.getLogger(CustomerDAO.class.getName()).log(Level.SEVERE, null, ex);
40 | }
41 | return null;
42 | }
43 |
44 | public static Statement createCustomerStatement(){
45 | try {
46 | Statement smt = con.createStatement();
47 |
48 | return smt;
49 | } catch (SQLException ex) {
50 | Logger.getLogger(CustomerDAO.class.getName()).log(Level.SEVERE, null, ex);
51 | }
52 | return null;
53 |
54 | }
55 | public static boolean deleteCustomer(int customer_id) {
56 | int status = 0;
57 | try {
58 | con = Connect.getConnection();
59 | if (con != null) {
60 | //Statement smt = con.createStatement();
61 |
62 | String query = "DELETE from customers where customerCode = " + customer_id + "";
63 | status = createCustomerStatement().executeUpdate(query);
64 | if (status > 0) {
65 | return true;
66 | }
67 | }
68 | } catch (SQLException ex) {
69 | Logger.getLogger(CustomerDAO.class.getName()).log(Level.SEVERE, null, ex);
70 | }
71 | return false;
72 | }
73 |
74 | public static boolean insertCustomer(Customer customer) {
75 | String d = ((customer.getDob().getYear() + 1900) + "-" + (customer.getDob().getMonth() + 1) + "-" + (customer.getDob().getDay()));
76 | int status = 0;
77 | try {
78 | con = Connect.getConnection();
79 | if (con != null) {
80 | String query = "INSERT into customers (NULL, firstname, middlename, lastname, address, city, state, country, c_code, mobile, email, dob, nok, gender)"
81 | + " values('" + customer.getFirstName() + "' ,'" + customer.getMiddleName() + "', '" + customer.getLastName() + "', "
82 | + "'" + customer.getAddress() + "', '" + customer.getCity() + "','" + customer.getState() + "' ,'" + customer.getState() + "', "
83 | + "'" + customer.getCountry() + "' , " + customer.getC_code() + "," + customer.getMobile() + ""
84 | + ", '" + customer.getEmail() + "','" + d + "' ,'" + customer.getNok() + "', '" + customer.getGender() + "')";
85 | status = createCustomerStatement().executeUpdate(query);
86 | if (status > 0) {
87 | return true;
88 | }
89 | }
90 | return false;
91 | } catch (SQLException ex) {
92 | Logger.getLogger(CustomerDAO.class.getName()).log(Level.SEVERE, null, ex);
93 | }
94 | return false;
95 | }
96 |
97 | public static boolean updateCustomer(Customer customer){
98 | int status = 0;
99 | try {
100 | con = Connect.getConnection();
101 | if(con != null){
102 | String query = "update from customers set firstname = '" + customer.getFirstName()+
103 | "', middlename = '" + customer.getMiddleName()+", lastname= '"
104 | + customer.getLastName()+ "', address= '" + customer.getAddress() + "' , city= '" + customer.getCity() +
105 | "', state= '"+ customer.getState()+ "', Country= '" + customer.getCountry()
106 | + "', c_code= '" + customer.getC_code()+ "', mobile= '" + customer.getMobile()
107 | +"', dob= '" + customer.getDob() + "', nok = '" + customer.getNok()
108 | + "', gender= '" + customer.getGender() + "' where customercode = " + customer.getCustomercode();
109 | status = createCustomerStatement().executeUpdate(query);
110 | if (status > 0){
111 | return true;
112 | }
113 |
114 | }
115 |
116 | } catch (SQLException ex) {
117 | Logger.getLogger(CustomerDAO.class.getName()).log(Level.SEVERE, null, ex);
118 | }
119 | return false;
120 | }
121 |
122 | public static ResultSet getCustomerbyData(String firstName, String middleName, String lastName, char gender, Date dob){
123 | char g = Character.toUpperCase(gender);
124 | String d = ((dob.getYear() + 1900) + "-" + (dob.getMonth() + 1) + "-" + (dob.getDay()));
125 | try {
126 | con = Connect.getConnection();
127 | if(con != null){
128 | String query = "SELECT * FROM customers where firstname= '" + (firstName.substring(0, 1).toUpperCase() + firstName.substring(1).toLowerCase())
129 | + "' and middlename= '" + (middleName.substring(0, 1).toUpperCase() + middleName.toLowerCase()) + "', lastname= '"
130 | + (lastName.substring(0, 1).toUpperCase() + lastName.substring(1).toLowerCase())+ "' and gender ='" + g + "'and dob = '" + d + "'";
131 | ResultSet rs = createCustomerStatement().executeQuery(query);
132 | return rs;
133 | }
134 | } catch (SQLException ex) {
135 | Logger.getLogger(CustomerDAO.class.getName()).log(Level.SEVERE, null, ex);
136 | }
137 | return null;
138 |
139 | }
140 |
141 | // This is when we have already created the customeraccount but we want to noraml fill in the details
142 | public static ResultSet getCustomerById(int customer_id){
143 |
144 | try {
145 | con = Connect.getConnection();
146 | if(con != null){
147 | String query = "SELECT * FROM customeraccount where customerCode= " + customer_id;
148 | ResultSet rs = createCustomerStatement().executeQuery(query);
149 | return rs;
150 | }
151 | } catch (SQLException ex) {
152 | Logger.getLogger(CustomerDAO.class.getName()).log(Level.SEVERE, null, ex);
153 | }
154 | return null;
155 | }
156 | }
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
--------------------------------------------------------------------------------
/gui/SwingExam.form:
--------------------------------------------------------------------------------
1 |
2 |
3 |
144 |
--------------------------------------------------------------------------------
/gui/SwingExam.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package gui;
7 |
8 | import javax.swing.JOptionPane;
9 |
10 | /**
11 | *
12 | * @author femitemiola
13 | */
14 | public class SwingExam extends javax.swing.JFrame {
15 |
16 | /**
17 | * Creates new form SwingExam
18 | */
19 | public SwingExam() {
20 | initComponents();
21 | }
22 |
23 | /**
24 | * This method is called from within the constructor to initialize the form.
25 | * WARNING: Do NOT modify this code. The content of this method is always
26 | * regenerated by the Form Editor.
27 | */
28 | @SuppressWarnings("unchecked")
29 | // //GEN-BEGIN:initComponents
30 | private void initComponents() {
31 |
32 | txtuser = new javax.swing.JLabel();
33 | lblPass = new javax.swing.JLabel();
34 | lbltextuserfield = new javax.swing.JTextField();
35 | buttonReset = new javax.swing.JButton();
36 | SubmitButtonTextfield = new javax.swing.JButton();
37 | jpasstextfield = new javax.swing.JPasswordField();
38 |
39 | setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
40 | setFont(new java.awt.Font("Lucida Grande", 0, 10)); // NOI18N
41 | setForeground(java.awt.Color.lightGray);
42 |
43 | txtuser.setFont(new java.awt.Font("Menlo", 0, 13)); // NOI18N
44 | txtuser.setForeground(new java.awt.Color(51, 0, 255));
45 | txtuser.setText("username");
46 |
47 | lblPass.setForeground(new java.awt.Color(0, 0, 255));
48 | lblPass.setText("pwd");
49 |
50 | lbltextuserfield.addActionListener(new java.awt.event.ActionListener() {
51 | public void actionPerformed(java.awt.event.ActionEvent evt) {
52 | lbltextuserfieldActionPerformed(evt);
53 | }
54 | });
55 |
56 | buttonReset.setFont(new java.awt.Font("Lucida Grande", 0, 14)); // NOI18N
57 | buttonReset.setForeground(new java.awt.Color(255, 153, 153));
58 | buttonReset.setText("Reset");
59 | buttonReset.addActionListener(new java.awt.event.ActionListener() {
60 | public void actionPerformed(java.awt.event.ActionEvent evt) {
61 | buttonResetActionPerformed(evt);
62 | }
63 | });
64 |
65 | SubmitButtonTextfield.setFont(new java.awt.Font("Lucida Grande", 0, 14)); // NOI18N
66 | SubmitButtonTextfield.setForeground(new java.awt.Color(255, 153, 153));
67 | SubmitButtonTextfield.setText("Sumbit");
68 | SubmitButtonTextfield.addActionListener(this::SubmitButtonTextfieldActionPerformed);
69 |
70 | javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
71 | getContentPane().setLayout(layout);
72 | layout.setHorizontalGroup(
73 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
74 | .addGroup(layout.createSequentialGroup()
75 | .addGap(12, 12, 12)
76 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
77 | .addGroup(layout.createSequentialGroup()
78 | .addComponent(lblPass, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
79 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
80 | .addGroup(layout.createSequentialGroup()
81 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
82 | .addComponent(buttonReset, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
83 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
84 | .addComponent(SubmitButtonTextfield)
85 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 37, Short.MAX_VALUE))
86 | .addGroup(layout.createSequentialGroup()
87 | .addGap(6, 6, 6)
88 | .addComponent(jpasstextfield))))
89 | .addGroup(layout.createSequentialGroup()
90 | .addComponent(txtuser, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
91 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
92 | .addComponent(lbltextuserfield)))
93 | .addGap(273, 273, 273))
94 | );
95 | layout.setVerticalGroup(
96 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
97 | .addGroup(layout.createSequentialGroup()
98 | .addGap(48, 48, 48)
99 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
100 | .addComponent(txtuser)
101 | .addComponent(lbltextuserfield, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
102 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
103 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
104 | .addGroup(layout.createSequentialGroup()
105 | .addComponent(lblPass, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
106 | .addGap(0, 12, Short.MAX_VALUE))
107 | .addComponent(jpasstextfield))
108 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
109 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
110 | .addComponent(buttonReset, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
111 | .addComponent(SubmitButtonTextfield, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
112 | .addGap(330, 330, 330))
113 | );
114 |
115 | pack();
116 | }// //GEN-END:initComponents
117 |
118 | private void buttonResetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonResetActionPerformed
119 | // TODO add your handling code here:
120 | jpasstextfield.setText("");
121 | lbltextuserfield.setText("");
122 | }//GEN-LAST:event_buttonResetActionPerformed
123 |
124 | private void lbltextuserfieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_lbltextuserfieldActionPerformed
125 | // TODO add your handling code here:
126 | }//GEN-LAST:event_lbltextuserfieldActionPerformed
127 |
128 | private void SubmitButtonTextfieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SubmitButtonTextfieldActionPerformed
129 | // TODO add your handling code here:
130 | String username = lbltextuserfield.getText();
131 | String pwd = jpasstextfield.getText();
132 | System.out.println("Username: " + username);
133 | System.out.println("password: " + pwd);
134 | JOptionPane.showMessageDialog(this, "Username: " + username + "\npwd: " + pwd );
135 | }//GEN-LAST:event_SubmitButtonTextfieldActionPerformed
136 |
137 | /**
138 | * @param args the command line arguments
139 | */
140 | public static void main(String args[]) {
141 | /* Set the Nimbus look and feel */
142 | //
143 | /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
144 | * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
145 | */
146 | try {
147 | for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
148 | if ("Nimbus".equals(info.getName())) {
149 | javax.swing.UIManager.setLookAndFeel(info.getClassName());
150 | break;
151 | }
152 | }
153 | } catch (ClassNotFoundException ex) {
154 | java.util.logging.Logger.getLogger(SwingExam.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
155 | } catch (InstantiationException ex) {
156 | java.util.logging.Logger.getLogger(SwingExam.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
157 | } catch (IllegalAccessException ex) {
158 | java.util.logging.Logger.getLogger(SwingExam.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
159 | } catch (javax.swing.UnsupportedLookAndFeelException ex) {
160 | java.util.logging.Logger.getLogger(SwingExam.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
161 | }
162 | //
163 |
164 | /* Create and display the form */
165 | java.awt.EventQueue.invokeLater(new Runnable() {
166 | public void run() {
167 | new SwingExam().setVisible(true);
168 | }
169 | });
170 | }
171 |
172 | // Variables declaration - do not modify//GEN-BEGIN:variables
173 | private javax.swing.JButton SubmitButtonTextfield;
174 | private javax.swing.JButton buttonReset;
175 | private javax.swing.JPasswordField jpasstextfield;
176 | private javax.swing.JLabel lblPass;
177 | private javax.swing.JTextField lbltextuserfield;
178 | private javax.swing.JLabel txtuser;
179 | // End of variables declaration//GEN-END:variables
180 | }
181 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/src/view/ATM.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package src.view;
7 |
8 | import java.util.Date;
9 | import java.util.Iterator;
10 | import java.util.Scanner;
11 | import src.controller.BankController;
12 | import src.model.CustomerAccountDAO;
13 | import src.model.entities.Accounts;
14 | import src.model.entities.Customer;
15 | import src.model.entities.CustomerAccount;
16 | import java.sql.ResultSet;
17 | import src.controller.CustomerController;
18 | import java.sql.SQLException;
19 | import java.util.logging.Level;
20 | import java.util.logging.Logger;
21 |
22 | /**
23 | *
24 | * @author femitemiola
25 | */
26 | public class ATM {
27 |
28 | private static Scanner input = new Scanner(System.in).useDelimiter("\n");
29 | private static BankController bank = new BankController();
30 | private static CustomerController customer = new CustomerController();
31 |
32 | public static void main(String[] args) {
33 | int option = -1;
34 | if (args.length > 0) {
35 | option = Integer.parseInt(args[0]);
36 | }
37 | System.out.println("Welcome to KEBank");
38 | boolean flag = true;
39 | while (flag) {
40 | if (option < 0) {
41 | option = 2;
42 | }
43 | {
44 | switch (option) {
45 | case 0:
46 | System.out.println("Thank you for banking with us");
47 | System.exit(0);
48 | case 1:
49 | String username = getDatawithLine("Enter Username: ");
50 | String pwd = getDatawithLine("Enter password: ");
51 | if (bank.authenticate(username, pwd)) {
52 | bank_Operation();
53 | } else {
54 | Logger.getLogger(ATM.class.getName());
55 | }
56 | break;
57 | case 2:
58 | String accountNo = getDatawithLine("Enter your account No: ");
59 | String pin = getDatawithLine("Enter pin");
60 | if (customer.authenticateCustomer(accountNo, pin)) {
61 | customer_Operation();
62 | } else {
63 | Logger.getLogger(ATM.class.getName());
64 | }
65 | break;
66 | default:
67 | Logger.getLogger(ATM.class.getName());
68 | break;
69 | }
70 | }
71 | break;
72 | }
73 |
74 | }
75 |
76 | private static Customer createorGetCustomer() {
77 | Customer newCustomer = null;
78 | String firstName = getUserData("Enter FirstName: ");
79 | String middleName = getUserData("EntelastName: ");
80 | String lastName = getUserData("EntelastName: ");
81 | char gender = getUserData("[M]: Male\n[[F]: Female\nEnter option: ").charAt(0);
82 | String date[] = getUserData("Enter Date of Birth: (dd-mm-yyyy): ").split(":");
83 | int d = Integer.parseInt(date[0]);
84 | int m = Integer.parseInt(date[1]);
85 | int y = Integer.parseInt(date[2]);
86 | Date dob = new Date(y - 1900, (m - 1), d);
87 |
88 | //check if the customer exists;
89 | newCustomer = bank.getCustomersbyData(firstName, middleName, lastName, gender, dob);
90 | if (newCustomer == null) {
91 | String address = getUserData("Enter Address: ");
92 | String city = getUserData("Enter city: ");
93 | String state = getUserData("Enter state: ");
94 | String country = getUserData("Enter Country : ");
95 | String ccode = getUserData("Enter Country Code: ");
96 | String mobile = getUserData("Enter mobile: ");
97 | String email = getUserData("Enter email: ");
98 | String nok = getUserData("Enter next of kin: ");
99 | String pin = getUserData("Enter pin: ");
100 |
101 | customer.insertCustomer((new Customer(-1, firstName, middleName, lastName, address,
102 | city, state, country, ccode, mobile, email, dob, nok, gender)));
103 |
104 | // New customer will return
105 | newCustomer = bank.getCustomersbyData(firstName, middleName, lastName, gender, dob);
106 | }
107 | return newCustomer;
108 | }
109 |
110 | private static int getAllAccountCodeType() {
111 | for (Iterator it = bank.getAllAccounts().iterator(); it.hasNext();) {
112 | Accounts account = (Accounts) it.next();
113 | if (account != null) {
114 | System.out.println("[" + account.getAccountcode() + " ]- " + account.getName());
115 | }
116 | }
117 | return Integer.parseInt(getUserData("Enter accounttype, pls enter option: "));
118 | }
119 |
120 | private static String getDatawithLine(String smt) {
121 | System.out.println(smt);
122 | return input.nextLine();
123 | }
124 |
125 | private static String getUserData(String smt) {
126 | System.out.println(smt);
127 | return input.next();
128 | }
129 |
130 | private static int getUserDataInt(String smt) {
131 | System.out.println(smt);
132 | return input.nextInt();
133 | }
134 |
135 | private static double getUserDataDouble(String smt) {
136 | System.out.println(smt);
137 | return input.nextDouble();
138 | }
139 |
140 | private static void bank_Operation() {
141 | while (true) {
142 | System.out.println("1: Check customer balance\n"
143 | + "2: Create new account\n "
144 | + "3: Delete an account\n "
145 | + "4: Show all account\n"
146 | + "5: Reset Customer PIN\n"
147 | + "6: Return to previous menu\n"
148 | + "Enter option: ");
149 |
150 | int selection = input.nextInt();
151 | switch (selection) {
152 | case 1:
153 | String accountNo = getUserData("Enter Account Number: ");
154 | System.out.println("Account balance is: " + bank.checkBalance(accountNo));
155 |
156 | case 2:
157 | int customerCode = createorGetCustomer().getCustomercode();
158 | System.out.println(customerCode);
159 | accountNo = getUserData("Enter your account number");
160 |
161 | // The account type
162 | int accountCode = getAllAccountCodeType();
163 | double balance = getUserDataDouble("Enter balance: ");
164 | if (bank.addCustomerAccount(new CustomerAccount(accountNo, customerCode, accountCode, "0000", balance, null, "Inactive"))) {
165 | System.out.println("Account was successfully added");
166 | } else {
167 | System.out.println("Sorry unsuccessful");
168 | }
169 | break;
170 | case 3:
171 | accountNo = getUserData("Enter the account you wish to delete: ");
172 | if (bank.deleteCustomerAccount(accountNo)) {
173 | System.out.println("Successfully deleted");
174 | } else {
175 | System.out.println("Unsuccessfully");
176 | }
177 | break;
178 |
179 | case 4:
180 | ResultSet rs = CustomerAccountDAO.getAllCustomersAccounts();
181 | {
182 | try {
183 | while (rs.next()) {
184 | System.out.printf("Account No: %s\nAccount Type: %s\n%f\n\n", rs.getString(1),
185 | rs.getString(2), rs.getString(3), rs.getDouble(4));
186 | }
187 | } catch (SQLException ex) {
188 | Logger.getLogger(ATM.class.getName()).log(Level.SEVERE, null, ex);
189 | }
190 | }
191 | break;
192 |
193 | case 5:
194 | default:
195 | break;
196 |
197 | }
198 | String status = getUserData("Do you want to perform another transaction (Y/N)").substring(0);
199 | if (status.equalsIgnoreCase("N")) {
200 | break;
201 | }
202 | }
203 | }
204 |
205 | private static void customer_Operation() {
206 | while (true) {
207 | System.out.print("1. My account balance is: \n"
208 | + "2. Make a deposit\n "
209 | + "3. Make a withdrawal \n"
210 | + "4. Make a transfer\n "
211 | + "5. Update Details \n "
212 | + "6. Show all my accounts \n"
213 | + "Enter your option");
214 | int selection = input.nextInt();
215 | switch (selection) {
216 | case 1:
217 | System.out.println("Your account balance is " + customer.checkBalance());
218 | case 2:
219 | double deposited_amount = getUserDataDouble("How much do you want to deposit");
220 | System.out.println("your new balance is" + customer.deposit(deposited_amount));
221 | case 3:
222 | double withdraw_amount = getUserDataDouble("How much do you want to deposit");
223 | System.out.println("Your new balance is = " + customer.withdraw(withdraw_amount));
224 | case 4:
225 | double transfered_amount = getUserDataDouble("How much do you want to transfer");
226 | String accountNo = getDatawithLine("Enter the account you wish to credit");
227 | System.out.println("You new balance is " + customer.Transfer_amount(accountNo, transfered_amount));
228 | System.out.println("You have transfered " + transfered_amount + "to Customer 2");
229 | case 5:
230 | System.out.println("1: update Lastname\n2: Update Address\n3: Change Pin\n4: Recover Pin");
231 | int option = getUserDataInt("Enter option: ");
232 | switch (option) {
233 | case 1:
234 | String newLastName = getUserData("Enter your new LastName: ");
235 | customer.updateCustomerlastName(newLastName);
236 | break;
237 | case 2:
238 | String address = getUserData("Enter your address: ");
239 | String city = getUserData("Enter your city: ");
240 | String State = getUserData("Enter your state: ");
241 | String newAddress = address + ":" + city + ":" + State;
242 | customer.updateAddress(newAddress);
243 | case 3:
244 | String oldPin = getUserData("Enter your old Pin: ");
245 | String newPin = getUserData("Enter your new Pin: ");
246 | String confirmPin = getUserData("Enter your confirm Pin: ");
247 | if (newPin.equals(confirmPin)) {
248 | if (customer.updateCustomerPin(oldPin, newPin)) {
249 | System.out.println("Pin successfully changed");
250 | } else {
251 | System.out.println("Visit our nearest branch");
252 | }
253 | } else {
254 | System.out.println("The new pin and confirm Pin does not match");
255 | }
256 | case 4:
257 | String email = getUserData("Enter email: ");
258 | if (email.equals(email)) {
259 | newPin = getUserData("Enter your new Pin: ");
260 | confirmPin = getUserData("Enter your confirm Pin: ");
261 | if (newPin.equals(confirmPin)) {
262 | if (customer.updateCustomerPin(confirmPin, newPin)) {
263 | System.out.println("Pin successfully changed");
264 | }
265 |
266 | }
267 |
268 | }
269 | break;
270 | case 6:
271 |
272 | default:
273 | break;
274 |
275 | }
276 | String customer_status = getUserData("Do you want you want to perform any transaction: ");
277 | if(customer_status.equalsIgnoreCase("N")){
278 | break;
279 | }
280 |
281 | }
282 | }
283 | }
284 |
285 | }
--------------------------------------------------------------------------------