Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** Radoslaw Burkacki
- * 29/05/2016
- * Bankingapp class
- * This class is a program driver
- * All menus are here and all of the program functionality is here */
- /** Importing libriaries*/
- import java.sql.*;
- import java.util.ArrayList;
- import java.util.InputMismatchException;
- import java.util.Random;
- import java.util.Scanner;
- /** Importing libriaries*/
- public class Bankingapp { /** Creating class called Bankingapp*/
- public static void main(String[] args) { /** Creating main class, when the program starts this method is loaded first!*/
- boolean isdbconnected=false; /** Creating new boolean variable*/
- isdbconnected = isDbConnected(); /**Setting isdbconnected to whatever will be returned from function isDbConnected*/
- if(isdbconnected == false){ /**if statement if isdbconnected equals to false then...*/
- System.out.println("Cannot connect to database."); /**display message*/
- }else if(isdbconnected){ /**if isd connected is equal to true then run program...*/
- Scanner sc = new Scanner(System.in); /**create new instance of scanner*/
- int menu=0; /** create variable menu as int*/
- String dbpath ="jdbc:mysql://localhost:3306/gradedunit2?autoReconnect=true&useSSL=false"; /** Creating a string called dbpath and setting its value to my database path. I will use it later to connect to my database */
- String dbid = "root"; /** Creating a string called dbit setting its value to root. I will use this variable each time i connect to database*/
- String dbpassword = "1234"; /** Creating a string called dbpassword setting its value to 1234. I will use this variable each time i connect to database*/
- do{ /** Starting loop*/
- System.out.println("___________________________________________________________________________________________________________"); /** Displaying message */
- System.out.println("1. Open New Account"); /** Displaying message */
- System.out.println("2. Login"); /** Displaying message */
- System.out.println("3. Exit"); /** Displaying message */
- System.out.println("Please enter 1-3"); /** Displaying message */
- try { /** Starting try statement(erro handling for menu(missmatchexception) */
- menu = sc.nextInt(); /** saving input from user to menu */
- } catch (InputMismatchException e) {/** Catchning missmatchexception occours when user enters string instead of numbers*/
- sc.nextLine(); /** clear buffer */
- }
- if(menu ==0 || menu >3) { /** if menu is equal to 0 or equal to more than 3 then ... */
- System.out.println("Please use numbers 1 to 3 to navigate throught menu"); /** Displaying message */
- } /** Close if statement */
- switch (menu){ /** starting switch statement(menu) */
- case 1: /** Starting case one. If menu = 1 then...*/
- String title = null, fname = null, lname = null, address = null, postcode = null, city = null; /** Create variables to store customer details*/
- sc.nextLine(); /** Clearing buffer*/
- System.out.println("Please enter title"); /** Displaying message */
- title = sc.nextLine(); /** Saving input from user to title */
- if(title.equals("")){ /** if title is empty then... */
- do{ /** Start loop */
- System.out.println("Please re-enter title"); /** Displaying message */
- title = sc.nextLine(); /** saving input from user to title */
- }while(title.equals("")); /** end loop when title is not empty
- p when title is not empty */
- } /** closing if statement */
- if(!Character.isUpperCase(title.charAt(0))){ /** if statement, if first letter of title is lower case then... */
- title = ToUpperCase(title); /** set title equal to(call function ToUpperCase and pass title into it) */
- } /** Close if */
- System.out.println("Please enter first name"); /** Displaying message */
- fname = sc.nextLine(); /** Saving input from user to fname */
- if(fname.equals("")){ /** if fname is empty then... */
- do{ /** Start loop */
- System.out.println("Please re-enter first name"); /** Displaying message */
- fname = sc.nextLine(); /** set fname to whatever was enterd by user*/
- }while(fname.equals("")); /** end loop when fname is not equal to nothing*/
- }/**close if */
- if(!Character.isUpperCase(fname.charAt(0))){ /** if if index 0 of fname is equal to lower letter thenn.. */
- fname = ToUpperCase(fname); /** set fname equal to(call function ToUpperCase and pass fname into it) */
- } /**close if*/
- System.out.println("Please enter last name"); /** Displaying message */
- lname = sc.nextLine(); /** set lname equal to input from user*/
- if(lname.equals("")){ /** start if statement if lname equals to nothing*/
- do{ /**start do while loop*/
- System.out.println("Please re-enter last name"); /** Displaying message */
- lname = sc.nextLine(); /** set lname equal to input from user*/
- }while(lname.equals("")); /** stop loop when lname is not equal to nothing*/
- } /**close if statement*/
- if(!Character.isUpperCase(lname.charAt(0))){ /** if index 0 of lname is lower case then...*/
- lname = ToUpperCase(lname); /** set lname equal to(call function ToUpperCase and pass lname into it) */
- }
- System.out.println("Please enter address"); /** Displaying message */
- address = sc.nextLine(); /** set address equal to input from user */
- if(address.equals("")){ /** if address is empty */
- do{ /** start do while loop */
- System.out.println("Please re-enter address"); /** Displaying message */
- address = sc.nextLine(); /** set address equal to input from user */
- }while(address.equals("")); /** ending loop if address it not empty */
- }
- System.out.println("Please enter postcode"); /** Displaying message */
- postcode = sc.nextLine(); /** set postcode equal to input from user */
- if(postcode.equals("")){ /** if postcode is empty */
- do{ /** start do while loop */
- System.out.println("Please re-enter postcode"); /** Displaying message */
- postcode = sc.nextLine(); /** set postcode equal to input from user*/
- }while(postcode.equals("")); /** end while loop when postcode is not empty */
- }
- System.out.println("Please enter city"); /** Displaying message */
- city = sc.nextLine(); /** set city equal to input from user */
- if(city.equals("")){ /** if city is empty then... */
- do{ /** start do while loop */
- System.out.println("Please enter re-city"); /** Displaying message */
- city = sc.nextLine(); /** set city equal to input from user */
- }while(city.equals("")); /** end while loop when city is not empty */
- }
- if(!Character.isUpperCase(city.charAt(0))){ /** if index 0 of city is lower case */
- city = ToUpperCase(city); /** set city equal to(call function ToUpperCase and pass city into it) */
- }
- /** Setting first letter of title,fname,lname,address,postcode and city to capital letter */
- Customer c = new Customer(title, fname , lname , city, postcode, address); /** Creating new object called c of customer class and passing parameters */
- int accountnumber=0,sortcode=0; String password=null,password2=null,accounttype = null; /** Creating new variables and setting values to null */
- /** Making sure that user has repeated has repeated his password */
- do{ /** Starting loop */
- System.out.println("Please enter your password"); /** Displaying message */
- password = sc.nextLine(); /** Reading input from user and saving it to variable password */
- System.out.println("Please reenter your password"); /** Displaying message */
- password2= sc.nextLine(); /** Reading input from user and saving it to variable password2 */
- if(!password.equals(password2)){ /** Creating if statement if password is not equal to password2 then ... */
- System.out.println("Passwords do not match"); /** Displaying message */
- }
- }while (!password.equals(password2)); /** closing loop, if password is the same as password2 then stop loop otherwise repeat loop */
- /** Making sure that user has repeated has repeated his password */
- /** Validating input from user user will be able to enter only "Standard" or "Premium" other wise error message will be displayed */
- do { /** Starting loop */
- System.out.println("Please select account type. Standard or Premium(£5)"); /** Displaying message */
- accounttype = sc.nextLine(); /** Getting input from user and saving it to accounttype variable */
- if(!Character.isUpperCase(accounttype.charAt(0))){ /** if character at index 0 of variable accounttype is not uppercase then*/
- accounttype= ToUpperCase(accounttype);
- }/** close if statement */
- if((!accounttype.equals("Standard")) & (!accounttype.equals("Premium"))){ /** Creating if statment, if input from user is not equal to "Standard" or "Premium" then ... */
- do{ /** Start new loop */
- System.out.println("Please select account type. Standard or Premium(£5)"); /** Display message */
- accounttype = sc.nextLine(); /** Getting input from user and saving it to accounttype variable */
- if(!Character.isUpperCase(accounttype.charAt(0))){ /** if character at index 0 of variable accounttype is not uppercase then*/
- accounttype = ToUpperCase(accounttype);
- }/** close if statement */
- }while((!accounttype.equals("Standard")) & (!accounttype.equals("Premium"))); /** closing loop, if accounttype is not equal to "Standard" or "Premium" then go back to loop other wise exit loop */
- } /** closing if statement */
- } while ((accounttype.equals("Standard")) & (accounttype.equals("Premium"))); /** closing loop, if acconttype equals to "Standard" or "Premium" then quit loop other wise loop again */
- /** Validating input from user user will be able to enter only "Standard" or "Premium" other wise error message will be displayed */
- Random r = new Random(); /** Creating new Random instance called r, will use that to generate random numbers */
- boolean repeat = true;
- do{ /** Start loop(need to make sure that unique account number is generated)*/
- accountnumber = 10000000 + r.nextInt(90000000); /** Generating random number (xxxxxxxx) which will be customers account number */
- sortcode = 100000 + r.nextInt(900000); /** Generating random number (xxxxxx) which will be customers sortcode */
- String sqlcommand8 = "SELECT AccountNumber FROM gradedunit2.account where AccountNumber = "+accountnumber; /** SQL command*/
- ArrayList <String> accnoexist = new ArrayList<String>(readdatabase(dbpath,dbid,dbpassword,sqlcommand8)); /** Creating array list called accnoexistt, calling a function readdatabase wich will return a arraylist with result of a query , passing variables (dbpath,dbid,dbpassword,sqlcommand8, anything that is returned by function readdatabase is saved into dbresult arraylist*/
- if(accnoexist.get(0).equals("NotFound")){ /** If accnoexists at index 0 equals to notnull then ... */
- repeat = false; /**set repeat to false */
- }
- }while(repeat); /** when repeat is set to false then stop looping */
- Account a = null; /** Create new account named a */
- if (accounttype.equals("Standard")){ /** if accounttype is equal to standard then... */
- a = new Standard(password, accountnumber, sortcode, accounttype); /** set a as Standard account and pass variables into it */
- }
- else if(accounttype.equals("Premium")){ /** if accounttype is equal to premium */
- a = new Premium(password, accountnumber, sortcode, accounttype); /** set a as Premium account and pass variables into it */
- }
- System.out.println("You opened your account. Your account number is: "+a.getAccountNumber()+" Your sort code is: " +a.getSortCode()); /** Displays message which customers account number and sort code */
- String sqlcommandd = "SELECT COUNT(*) FROM customer"; /** Create new string and set its value to a sql command*/
- ArrayList <String> noofrows1 = new ArrayList<String>(readdatabase(dbpath,dbid,dbpassword,sqlcommandd));
- /** Creating array list, calling a function readdatabase wich will return a arraylist with result of a query
- * passing variables (dbpath,dbid,dbpassword,sqlcommandd), anything that is returned by function readdatabase is saved into arraylisy*/
- int noofrows = Integer.parseInt(noofrows1.get(0)); /** create new int and set its value to noofrows1 at index 0 (convert it to string)*/
- noofrows ++; /** Increase noofrows by 1*/
- /** adding new customer to account in database */
- Connection conn1 = null; /** Create new connection*/
- Statement stmt1 = null; /** Create new statement*/
- try /** Start new try block*/
- {
- conn1 = DriverManager.getConnection(dbpath,dbid,dbpassword); /** let connection connect to database and pass parameters*/
- stmt1 = conn1.createStatement();
- stmt1.execute("INSERT INTO Customer (Title,FirstName,LastName,Address,PostCode,City)"+ "VALUES ('"+c.getTitle()+"','"+c.getFName()+"','"+c.getLName()+"','"+c.getAddress()+"','"+c.getPostCode()+"','"+c.getCity()+"')");
- /** executeing sql command*/
- stmt1.execute("INSERT INTO Account (CustomerID,Password,AccountNumber,SortCode,Balance,AccountType) "+ "VALUES ('"+noofrows+"','"+a.getPassword()+"','"+a.getAccountNumber()+"','"+a.getSortCode()+"','"+a.getBalance()+"','"+a.getAccountType()+"')");
- /** executeing sql command*/
- } catch (Exception d) { /** Catching exception*/
- d.printStackTrace(); /** printing error message*/
- }finally {
- try { /**Starting try block*/
- stmt1.close(); /** close statement*/
- conn1.close(); /** close connection*/
- } catch (Exception e){}
- }
- break; /** end of case 1*/
- case 2: /**if user enterd 2 then...*/
- String accnoinput=null; /**Create new string*/
- String passwordinput=null; /**Create new String*/
- String dbaccounttype=null, dbsortcode=null, dbcustomerid = null, dbpass = null, dbaccno = null, dbtitle=null, dbfname=null,dblname=null; double dbbalance=0.00; /**Create variables*/
- sc.nextLine(); /**clearing buffer*/
- System.out.println("Please enter your account number"); /**Displaying message*/
- accnoinput = sc.nextLine(); /**Saving input from user to accnoinput*/
- System.out.println("Please enter your password"); /**Displaying message*/
- passwordinput = sc.nextLine(); /**Saving input from user to passwordinput*/
- ////////////////////////////////////// Reaeding from database (CustomerID, AccountNumber, Password)
- Connection conn2 = null; /**create new connection */
- Statement stmt2 = null; /**create new statement */
- ResultSet rows2 = null; /**create new result set */
- try { /** start try block */
- Class.forName("com.mysql.jdbc.Driver");
- conn2 = DriverManager.getConnection(dbpath,dbid,dbpassword); /**connect to database and pass parameters into it @param dbpath, @param dbid, @param dbpassword */
- stmt2 = conn2.createStatement();
- rows2 = stmt2.executeQuery("Select account.AccountType, account.SortCode, account.CustomerID, account.AccountNumber, account.Password, account.Balance, customer.Title, customer.FirstName, customer.LastName FROM customer, account WHERE account.AccountNumber = "+accnoinput+" and customer.CustomerID = (select account.CustomerID where account.AccountNumber);");
- /** run sql command */
- while(rows2.next()){ /** if rows2(return from sql statement) is NOT empty then loop*/
- dbaccounttype = rows2.getString("AccountType"); /**set dbaccounttype equal to whatever is inside in AccountType */
- dbsortcode = rows2.getString("SortCode"); /** set dbsortcode equal to whatever is inside SortCode column */
- dbcustomerid = rows2.getString("account.CustomerID"); /**set dbcustomerid equal to whatever is inside CustomerID column */
- dbaccno = rows2.getString("AccountNumber"); /**set dbaccno equal to whatever is inside AccountNumber column */
- dbpass = rows2.getString("Password"); /**set dbpass equal to whatever is inside Password column */
- dbbalance = rows2.getDouble("Balance"); /**set dbbalance equal to whatever is inside Balance column */
- dbtitle = rows2.getString("Title"); /**set dbtitle equal to whatever is inside Title column */
- dbfname = rows2.getString("FirstName"); /**set dbfname equal to whatever is inside FirstName column */
- dblname = rows2.getString("LastName"); /**set dblname equal to whatever is inside LastName column */
- }
- }catch (SQLException ex) { /** Catching sqlexception error*/
- System.out.println("SQLException: " + ex.getMessage());
- System.out.println("VendorError: " + ex.getErrorCode());
- } catch (ClassNotFoundException e) { /**Catching errors*/
- e.printStackTrace();
- } finally {
- try { /** starting try block*/
- rows2.close(); /**closing resultset*/
- stmt2.close(); /**closing statement*/
- conn2.close(); /**closing connection*/
- } catch (Exception e){} /**Catching errors*/
- }
- try{ /**Starting try block*/
- if (dbaccno.equals(accnoinput)){ /** Checking if account number was found in database */
- if(dbpass.equals(passwordinput)){ /** checking if password matches */
- if(dbaccounttype.equals("Standard") || dbaccounttype.equals("Premium")){ /** if accounttype is equal to standard or premium then run menu for users */
- do{ /**Starting do while loop*/
- System.out.println("___________________________________________________________________________________________________________");
- System.out.println("Welcome " + dbtitle + " " + dbfname + " " + dblname + " | Your account number : " + dbaccno ); /**Display message*/
- System.out.println("1. Transfer funds"); /**Display message*/
- System.out.println("2. Check balance"); /**Display message*/
- System.out.println("3. View Statement"); /**Display message*/
- System.out.println("4. Manage loan"); /**Display message*/
- System.out.println("5. Upgrade account"); /**Display message*/
- System.out.println("6. Logout");/**Display message*/
- System.out.println("Please enter 1-6"); /**Display message*/
- menu = 0; /**Setting menu equal to 0*/
- try { /**Starting try block*/
- menu = sc.nextInt(); /** menu equals to input from user*/
- } catch (InputMismatchException e) { /**Catching inputmissmatch exception*/
- sc.nextLine(); /**Clearing buffer*/
- }
- if(menu ==0 || menu >6) { /**if menu is equal to 0 or greater than 6 then....*/
- System.out.println("Please use numbers 1 to 6 to navigate throught menu"); /**display message*/
- }
- switch(menu){ /**starting switch statement*/
- case 1: /**if menu is equal to 1 then....*/
- String raccno= null, rsortcode=null, rtitle=null, rfname=null, rlname=null; double amount; /**create variables*/
- sc.nextLine(); /**clear buffer*/
- System.out.println("Please enter receivers account number"); /**display message*/
- raccno = sc.nextLine(); /**set value of raccno equal to input from user*/
- if(raccno.equals(dbaccno)) /** If customer accno is equal to own acc no and sortcode is equal to own sort code then*/
- {
- System.out.println("You cant send cash to yourself");/**displaying message*/
- }
- else if(!raccno.equals(dbaccno)){ /**if raccno is different than customers(logged in) then...*/
- System.out.println("Please enter receivers sortcode"); /** display message*/
- rsortcode = sc.nextLine(); /**save input from user*/
- System.out.println("Please enter amount you want to send"); /**display message*/
- amount = sc.nextDouble(); /**save input from user*/
- if(amount > dbbalance) { /** if customer wants to send more cash than he have then...*/
- System.out.println("You want to send more cash than you have."); /**display message*/
- }
- else if(dbbalance <= 0){ /**checking uf customer has enough cash*/
- System.out.println("Your dont have enought cash."); /**display message*/
- }
- else if(amount <= dbbalance){ /** if customer has enough cash then get receiver details from database*/
- String s = "Select account.SortCode, account.Balance, customer.Title, customer.FirstName, customer.LastName FROM customer, account WHERE account.AccountNumber =" + raccno + " and account.SortCode = "+ rsortcode +" and customer.CustomerID = (select account.CustomerID where account.AccountNumber)";
- /**create new string called s and set its value to sqlcommand*/
- ArrayList <String> dbresult = new ArrayList<String>(readdatabase(dbpath,dbid,dbpassword,s));
- /** Creating array list called dbresult, calling a function readdatabase wich will return a arraylist with result of a query
- * , passing variables (dbpath,dbid,dbpassword,s(sql command), anything that is returned by function readdatabase is saved into dbresult arraylist*/
- if(dbresult.get(0).equals("NotFound")){ /** if function readdatabase returns arraylist with index0 = NotFound then error*/
- System.out.println("Receiver doesnt exist. Make sure u enterd right acc no and sort code"); /** Displays message*/
- }
- else if(!dbresult.get(0).equals("NotFound")){ /** if function readdatabase returns arraylist with index0 = anything else than NotFound then account found*/
- System.out.printf("Transfer was succesful! £" + amount + " was removed from your account."); /**display message*/
- System.out.print("\n");
- /** make a note in statment table about transfer*/
- double receiverbalance = Double.parseDouble(dbresult.get(1)); /**convert from string to double and set value of receiverbalance equal to it*/
- double receiverbalancetotal = receiverbalance + amount; /** amount after transfer was added*/
- double senderbalancetotal = dbbalance - amount; /** senderbalancetotal = balance of sender with deductions*/
- String sendingcashto = "Sent cash to : " +raccno + " " + dbresult.get(0); /**setting value of sendigcashto*/
- String receivingcashfrom = "Received from: " + dbaccno + " " +dbsortcode; /**setting value of receivingcashfrom*/
- Connection conn3 = null; /**create new conncetion*/
- Statement stmt3 = null; /**create new syatement*/
- try /**statring try block*/
- {
- conn3 = DriverManager.getConnection(dbpath,dbid,dbpassword); /**connect to database and pass parameters, @param dbpath @param dbid @param dbpassword*/
- stmt3 = conn3.createStatement();
- stmt3.execute("INSERT INTO statement (AccountID, Details,CashIn,CashOut,Balance) VALUES ((SELECT AccountID FROM account WHERE AccountNumber = "+ dbaccno +"),'"+ sendingcashto +"',0.00, "+amount+", "+senderbalancetotal+");"); /**sql statement*/
- stmt3.execute("INSERT INTO statement (AccountID, Details,CashIn,CashOut,Balance) VALUES ((SELECT AccountID FROM account WHERE AccountNumber = "+ raccno +"),'"+ receivingcashfrom +"',"+amount+",0.00, "+receiverbalancetotal+");"); /**sql statement*/
- } catch (Exception d) { /**catching errors*/
- d.printStackTrace();
- }finally {
- try { /**starting try block*/
- stmt3.close(); /**closing statement*/
- conn3.close(); /**closing connection*/
- } catch (Exception e){} /**catching errors*/
- }
- /** update balance after cash was moved*/
- double cal1 = Double.parseDouble(dbresult.get(1)); /**create new variable, convert string to double(dbresult at index 1) and set it equal to new variable*/
- cal1 = cal1 + amount; /**do calulation add amount to balance*/
- dbbalance = dbbalance - amount; /**do calulation substract amount from balance*/
- String sqlcommand3 = "UPDATE account SET Balance ='" + receiverbalancetotal + "' WHERE AccountNumber = " +raccno; /**sql command*/
- String sqlcommand4 = "UPDATE account SET Balance ='" + senderbalancetotal + "' WHERE AccountNumber = " +dbaccno; /**sql command*/
- updatedatabase(dbpath,dbid,dbpassword,sqlcommand3); /**call function and pass parameters into it @param dbpath , @param dbit , @param dbpassword , @param sqlcommand3*/
- updatedatabase(dbpath,dbid,dbpassword,sqlcommand4); /**call function and pass parameters into it @param dbpath , @param dbit , @param dbpassword , @param sqlcommand4*/
- dbresult.clear(); /**clear array*/
- }
- }
- }
- break;
- case 2: /** Display balance */
- System.out.printf("Your balance is: £%.2f", dbbalance ); /**display message*/
- System.out.printf("\n");
- break;
- case 3: /** Display statemenet */
- Connection conn3 = null; /**creating new connection*/
- Statement stmt3 = null; /**creating new statement*/
- ResultSet rows3 = null; /**creating new result set*/
- try {
- Class.forName("com.mysql.jdbc.Driver");
- conn3 = DriverManager.getConnection(dbpath,dbid,dbpassword); /**connect to database*/
- stmt3 = conn3.createStatement();
- String sqlcommand = "Select statement.Date, statement.Details, statement.CashIn,statement.CashOut, statement.Balance FROM account , statement WHERE statement.AccountID = (Select account.AccountID WHERE account.AccountNumber ="+ dbaccno + ")"; /**create sql command*/
- rows3 = stmt3.executeQuery(sqlcommand); /**send sql command to database*/
- System.out.println("___________________________________________________________________________________________________________"); /**display message*/
- System.out.println(" Date | Details | CashIn| CashOut| Balance"); /**display message*/
- while(rows3.next()){ /** start while loop*/
- String date, cashin, cashout, balance; /**call variables*/
- System.out.println("___________________________________________________________________________________________________________"); /**display message*/
- date = rows3.getString("Date"); /**set date equal to whatever is inside Date column*/
- date = date.substring(0, 19); /**date will only have 19 characters */
- System.out.print(date); /**display message*/
- System.out.print(" | ");/**display message*/
- System.out.print(rows3.getString("Details"));
- System.out.print(" | ");/**display message*/
- cashin = rows3.getString("CashIn"); /**set cashin equal to whatever is inside CashIn column*/
- cashin =SetFormat(cashin); /**call function SetFormat and pass cahin into it and set cahin equal to whatever is returned by this function*/
- System.out.print(cashin);/**display message*/
- System.out.print("| ");/**display message*/
- cashout = rows3.getString("CashOut"); /**set cashout equal to whatever is inside CashOut column*/
- cashout = SetFormat(cashout);/**call function SetFormat and pass cashout into it and set cashout equal to whatever is returned by this function*/
- System.out.print(cashout); /**display message*/
- System.out.print("| ");/**display message*/
- balance = rows3.getString("Balance");/**set balance equal to whatever is inside Balance column*/
- balance = SetFormat(balance); /**call function SetFormat and pass balance into it and set balance equal to whatever is returned by this function*/
- System.out.print(balance);/**display message*/
- System.out.print(" \n");
- }
- }
- catch (SQLException ex) { /**catch errors*/
- System.out.println("SQLException: " + ex.getMessage()); /**display message*/
- System.out.println("VendorError: " + ex.getErrorCode());/**display message*/
- }
- catch (ClassNotFoundException e) { /**catch errors*/
- e.printStackTrace();
- }
- break;
- case 4: /** Apply for a loan */
- String sqlcommand = "Select AccountID, LoanAmount,Status from loan where AccountID =" + dbcustomerid; /**create new string variable*/
- ArrayList <String> dbresult = new ArrayList<String>(readdatabase(dbpath,dbid,dbpassword,sqlcommand));
- /** Creating array list called dbresult, calling a function readdatabase wich will return a arraylist with result of a query
- * , passing variables (dbpath,dbid,dbpassword,sqlcommand) anything that is returned by function readdatabase is saved into dbresult arraylist*/
- if(dbresult.get(0).equals("NotFound")){ /** if user has no loan then allow him to apply */
- sc.nextLine(); /**clear buffer*/
- System.out.println("How much you want to loan?");/**display message*/
- double loanamount = sc.nextDouble(); /**get input from user*/
- Connection conn4 = null; /**create new connection*/
- Statement stmt4 = null; /**create new statement*/
- try { /**start try block*/
- conn4 = DriverManager.getConnection(dbpath,dbid,dbpassword); /**connect to database and pass parameters*/
- stmt4 = conn4.createStatement();
- stmt4.execute("INSERT INTO Loan (AccountID,LoanAmount,Status) VALUES ("+dbcustomerid+",'"+loanamount+"','Pending')"); /**run command*/
- System.out.println("You have applied for a loan"); /**display message*/
- } catch (Exception d) {/**catch errors*/
- d.printStackTrace();
- }finally {
- try {
- stmt4.close(); /**close statement*/
- conn4.close(); /**close connection*/
- } catch (Exception e){} /**catch errors*/
- }
- }
- else if ((dbresult.get(0).equals(dbcustomerid)) & (dbresult.get(2).equals("Pending"))){ /** if user has already applied and state equals to pending */
- System.out.println("You already applied for loan, current status:"+ dbresult.get(2));/**display message*/
- }
- else if(dbresult.get(2).equals("Accepted")){ /** if loan was accepted then...*/
- System.out.println("Your loan was accepted £" + dbresult.get(1)+"."); /** Display message */
- System.out.println("Would you like to payoff loan now? Yes/No"); /** Display message */
- sc.nextLine(); /**clear buffer*/
- String pay=null; /**create new string*/
- pay = sc.nextLine(); /**set pay eqal to input*/
- if(!Character.isUpperCase(pay.charAt(0))){ /**if pay index 0 is equal to lower letter then...*/
- pay = ToUpperCase(pay); /**set pay to upper case*/
- }
- if(pay.equals("Yes")){ /**if pay is eqal to yes then...*/
- System.out.println("How much you want to pay?");/**display message*/
- double amount1;
- amount1 = sc.nextDouble();
- double loan = Double.parseDouble(dbresult.get(1));
- if(amount1 > loan){
- System.out.println("You cant pay more than you borrowed!"); /**display message*/
- }
- else if(amount1 < loan){
- loan = loan - amount1;
- dbbalance = dbbalance - amount1;
- String sqlcommand8= "UPDATE loan SET LoanAmount ="+loan+" where AccountID ="+dbcustomerid; /**sql command*/
- updatedatabase(dbpath,dbid,dbpassword,sqlcommand8); /**calling method updatedatabase and passing parameters into it*/
- String sqlcommand1 = "UPDATE account SET Balance ='" + dbbalance + "' where account.AccountNumber = "+dbaccno+" and account.sortcode ="+dbsortcode;/**sql command*/
- updatedatabase(dbpath,dbid,dbpassword,sqlcommand1);/**calling method updatedatabase and passing parameters into it*/
- // need to add note in statement
- /** Insert row into statement*/
- Connection conn11 = null; /**creating new connection*/
- Statement stmt11 = null;
- try/**start try block*/
- {
- conn11 = DriverManager.getConnection(dbpath,dbid,dbpassword);
- stmt11 = conn11.createStatement();
- stmt11.execute("INSERT INTO statement (AccountID, Details,CashIn,CashOut,Balance) VALUES ("+dbcustomerid+", ' Repay a loan ',0.00,"+amount1+","+dbbalance+");");
- } catch (Exception d) {/**catch errors*/
- d.printStackTrace();
- }finally {
- try {
- stmt11.close();
- conn11.close();
- } catch (Exception e){} /**catch errors*/
- }
- /** Insert row into statement*/
- }
- else if(amount1 <= loan){ /**if */
- /** Insert row into statement*/
- Connection conn11 = null;
- Statement stmt11 = null;
- try/**start try block*/
- {
- conn11 = DriverManager.getConnection(dbpath,dbid,dbpassword);
- stmt11 = conn11.createStatement();
- stmt11.execute("delete from loan where AccountID = "+dbcustomerid+";");
- } catch (Exception d) {/**catch errors*/
- d.printStackTrace();
- }finally {
- try { /**start try block*/
- stmt11.close();
- conn11.close();
- } catch (Exception e){}/**catch errors*/
- }
- /** Insert row into statement*/
- dbbalance = dbbalance - amount1;
- String sqlcommand1 = "UPDATE account SET Balance = "+dbbalance+" where account.AccountNumber = "+dbaccno+" and account.sortcode ="+dbsortcode;
- updatedatabase(dbpath,dbid,dbpassword,sqlcommand1);// updating balance
- Connection conn12 = null;
- Statement stmt12 = null;
- try/**start try block*/
- {
- conn12 = DriverManager.getConnection(dbpath,dbid,dbpassword);
- stmt12 = conn12.createStatement();
- stmt12.execute("INSERT INTO statement (AccountID, Details,CashIn,CashOut,Balance) VALUES ("+dbcustomerid+", ' Repay a loan ',0.00,"+amount1+","+dbbalance+")");
- } catch (Exception d) {/**catch errors*/
- d.printStackTrace();
- }finally {
- try { /**start try block*/
- stmt12.close();
- conn12.close();
- } catch (Exception e){}/**catch errors*/
- }
- /** Insert row into statement*/
- }
- else if(amount1 > dbbalance){
- System.out.println("You dont have enought cash");/**display message*/
- }
- }
- }
- else if(dbresult.get(2).equals("Declined")){
- System.out.println("Your loan was Declined");/**display message*/
- }
- break;
- case 5: /** Upgrade to premium */
- sc.nextLine();
- if(dbaccounttype.equals("Premium")){
- System.out.println("You are already premium!");/**display message*/
- }
- else if(dbaccounttype.equals("Standard")){
- System.out.println("Cost of premium is £5.00. Would you like to upgrade? Yes/No");/**display message*/
- String upgrade=null;
- upgrade = sc.nextLine();
- if(!Character.isUpperCase(upgrade.charAt(0))){
- upgrade = ToUpperCase(upgrade);
- }
- if(upgrade.equals("Yes")){ /**if upgrade equals to yes then....*/
- dbbalance = dbbalance - 5.00; /**do calculation*/
- String sqlcommand4 = "UPDATE account SET Balance ='" + dbbalance + "' where account.AccountNumber = "+dbaccno+" and account.sortcode ="+dbsortcode;
- String sqlcommand5 = "UPDATE account SET AccountType = 'Premium' where account.AccountNumber = "+dbaccno+" and account.sortcode ="+dbsortcode;
- updatedatabase(dbpath,dbid,dbpassword,sqlcommand4);
- updatedatabase(dbpath,dbid,dbpassword,sqlcommand5);
- System.out.println("£5.00 was removed from your account. Now you are premium member!");/**display message*/
- dbaccounttype = "Premium";
- Connection conn12 = null;
- Statement stmt12 = null;
- try/**start try block*/
- {
- conn12 = DriverManager.getConnection(dbpath,dbid,dbpassword);
- stmt12 = conn12.createStatement();
- stmt12.execute("INSERT INTO statement (AccountID, Details,CashIn,CashOut,Balance) VALUES ("+dbcustomerid+", ' Upgrade Account ',0.00,5.00,"+dbbalance+")");
- } catch (Exception d) {/**catch errors*/
- d.printStackTrace();
- }finally {
- try { /**start try block*/
- stmt12.close();
- conn12.close();
- } catch (Exception e){} /**catch errors*/
- }
- /** Insert row into statement*/
- }
- }
- break;
- }
- }while(menu != 6); /**quit loop when menu is eqal to 6*/
- }
- else if(dbaccounttype.equals("Staff")){ /** if accounttype is equal to Staff then run menu for staff */
- do{
- System.out.println("___________________________________________________________________________________________________________"); /**display message*/
- System.out.println("1. Add cash to user accounts(Deposit)"); /**display message*/
- System.out.println("2. Remove cash from user accounts(Withdraw)"); /**display message*/
- System.out.println("3. Accept or decline loan"); /**display message*/
- System.out.println("4. Logout"); /**display message*/
- System.out.println("Please enter 1-4");/**display message*/
- menu = 0;
- try { /**start try block*/
- menu = sc.nextInt();
- } catch (InputMismatchException e) {
- sc.nextLine();
- }
- if(menu ==0 || menu >4) { /** if menu is equal to 0 or equal to more than 3 then ... */
- System.out.println("Please use numbers 1 to 3 to navigate throught menu"); /** Displaying message */
- } /** Close if statement */
- switch(menu){
- case 1: /** Adding cash to user account(Deposit) */
- sc.nextLine();
- String accnoo=null,sortcodee=null;
- System.out.println("Please enter account number");/**display message*/
- accnoo = sc.nextLine(); /**save input from user*/
- System.out.println("Please enter sort code");/**display message*/
- sortcodee = sc.nextLine();/**save input from user*/
- String s = "Select account.Balance FROM account where account.AccountNumber = "+accnoo+" and account.sortcode ="+sortcodee;
- ArrayList <String> dbresult = new ArrayList<String>(readdatabase(dbpath,dbid,dbpassword,s));
- /** Creating array list called dbresult, calling a function readdatabase wich will return a arraylist with result of a query
- * , passing variables (dbpath,dbid,dbpassword,s(sql command), anything that is returned by function readdatabase is saved into dbresult arraylist*/
- if(!dbresult.get(0).equals("NotFound")){
- System.out.println("That customer does have £" + dbresult.get(0));/**display message*/
- System.out.println("How much you want to add?");/**display message*/
- double amount = sc.nextDouble();/**save input from user*/
- double bal = Double.parseDouble(dbresult.get(0));
- bal = bal + amount;
- String sqlcommand2 = "UPDATE account SET Balance ='" + bal + "' where account.AccountNumber = "+accnoo+" and account.sortcode ="+sortcodee;
- updatedatabase(dbpath,dbid,dbpassword,sqlcommand2);
- System.out.println("You added £" + amount + " Successfully");/**display message*/
- /** Insert row into statement*/
- Connection conn33 = null;
- Statement stmt33 = null;
- try/**start try block*/
- {
- conn33 = DriverManager.getConnection(dbpath,dbid,dbpassword);
- stmt33 = conn33.createStatement();
- stmt33.execute("INSERT INTO statement (AccountID, Details,CashIn,CashOut,Balance) VALUES ((Select AccountID from Account where AccountNumber = "+accnoo+"), ' Cash Deposited ',"+amount+",0.00,"+bal+")");
- } catch (Exception d) {/**catch errors*/
- d.printStackTrace();
- }finally {
- try { /**start try block*/
- stmt33.close();
- conn33.close();
- } catch (Exception e){} /**catch errors*/
- }
- /** Insert row into statement*/
- }
- else
- {
- System.out.println("User cannot be found");/**display message*/
- }
- break;
- case 2:/** Removing cash to user account(Withdraw) */
- sc.nextLine();
- String accnoo1=null,sortcodee1=null;
- System.out.println("Please enter account number");/**display message*/
- accnoo1 = sc.nextLine();/**save input from user*/
- System.out.println("Please enter sort code");/**display message*/
- sortcodee1 = sc.nextLine();/**save input from user*/
- String sqlcommand = "Select account.Balance FROM account where account.AccountNumber = "+accnoo1+" and account.sortcode ="+sortcodee1;
- ArrayList <String> dbresult1 = new ArrayList<String>(readdatabase(dbpath,dbid,dbpassword,sqlcommand));
- /** Creating array list called dbresult, calling a function readdatabase wich will return a arraylist with result of a query
- * , passing variables (dbpath,dbid,dbpassword,s(sql command), anything that is returned by function readdatabase is saved into dbresult arraylist*/
- if(!dbresult1.get(0).equals("NotFound")){
- System.out.println("That customer does have £" + dbresult1.get(0));/**display message*/
- System.out.println("How much you want to remove?");/**display message*/
- double amount1 = sc.nextDouble();/**save input from user*/
- double bal1 = Double.parseDouble(dbresult1.get(0));
- if(amount1 <= bal1){
- bal1 = bal1 - amount1;
- String sqlcommand1 = "UPDATE account SET Balance ='" + bal1 + "' where account.AccountNumber = "+accnoo1+" and account.sortcode ="+sortcodee1;
- updatedatabase(dbpath,dbid,dbpassword,sqlcommand1);
- System.out.println("You removed £" + amount1 + " Successfully");/**display message*/
- /** Insert row into statement*/
- Connection conn22 = null;
- Statement stmt22 = null;
- try/**start try block*/
- {
- conn22 = DriverManager.getConnection(dbpath,dbid,dbpassword);
- stmt22 = conn22.createStatement();
- stmt22.execute("INSERT INTO statement (AccountID, Details,CashIn,CashOut,Balance) VALUES ((Select AccountID from Account where AccountNumber = "+accnoo1+"), ' Cash Withdrawn ',"+amount1+",0.00,"+bal1+")");
- } catch (Exception d) {/**catch errors*/
- d.printStackTrace();
- }finally {
- try { /**start try block*/
- stmt22.close();
- conn22.close();
- } catch (Exception e){} /**catch errors*/
- }
- /** Insert row into statement*/
- }
- else{
- System.out.println("Cannot withdraw more then user has on account");/**display message*/
- }
- }else
- {
- System.out.println("User cannot be found");/**display message*/
- }
- break;
- case 3:
- /** Getting all the loans that are pending */
- String sqlcommand6 = "SELECT AccountID, LoanAmount, Status from loan where Status = 'Pending'";
- ArrayList <String> dbresult2 = new ArrayList<String>(readdatabase(dbpath,dbid,dbpassword,sqlcommand6));
- /** if no loan found then*/
- if(dbresult2.get(0).equals("NotFound")){
- System.out.println("No pedning loans");/**display message*/
- }
- else{
- System.out.println("Id, amount, status");
- for(int i =0; i < dbresult2.size()-1; i++){
- System.out.print(dbresult2.get(i) + " ");
- if(dbresult2.get(i).equals("Pending")){
- System.out.println();/**display message*/
- }
- }
- System.out.println("Please make sure that you pick a valid id");/**display message*/
- int select=0;
- boolean isint=false;
- do{
- System.out.println("Select record");/**display message*/
- try { /**start try block*/
- select = sc.nextInt();
- isint = false;
- } catch (InputMismatchException e) {
- sc.nextLine();
- isint=true;
- }
- }while(isint);
- System.out.println("Accept or decline?"); /**display message*/
- sc.nextLine();
- String accdec = sc.nextLine();/**save input from user*/
- if(!Character.isUpperCase(accdec.charAt(0))){ //
- accdec = ToUpperCase(accdec);
- }
- if(accdec.equals("Accept")){// when accepted then
- /** 1 update loan table
- * 2 update balance
- * 3 insert new row into statemenet
- * */
- /** Update loan table*/
- String sqlcommand7 = "UPDATE loan SET Status = 'Accepted' where AccountID =" + select;
- updatedatabase(dbpath,dbid,dbpassword,sqlcommand7);
- /** Update loan table*/
- /** Update balance table*/
- String sqlcommand9 = "UPDATE account SET Balance = Balance+ (Select LoanAmount from loan where AccountID = "+select+") WHERE AccountID = "+select; /***/
- updatedatabase(dbpath,dbid,dbpassword,sqlcommand9);
- /** Update balance table*/
- /** Insert row into statement*/
- Connection conn3 = null;
- Statement stmt3 = null;
- try/**start try block*/
- {
- conn3 = DriverManager.getConnection(dbpath,dbid,dbpassword);
- stmt3 = conn3.createStatement();
- stmt3.execute("INSERT INTO statement (AccountID, Details,CashIn,CashOut,Balance) VALUES ("+select+", ' Loan Accepted ',(Select LoanAmount from loan where AccountID = "+select+"),0.00,(Select Balance from Account where AccountID = "+select+"))");
- } catch (Exception d) {/**catch errors*/
- d.printStackTrace();
- }finally {
- try { /**start try block*/
- stmt3.close();
- conn3.close();
- } catch (Exception e){} /**catch errors*/
- }
- /** Insert row into statement*/
- System.out.println("Loan Accepted!");
- }
- else if(accdec.equals("Declined")){ /** If accdec equals to Declined then...*/
- String sqlcommand7 = "UPDATE loan SET Status = 'Declined' where AccountID =" + select; /** set sqlcommand7 equal to ... */
- updatedatabase(dbpath,dbid,dbpassword,sqlcommand7); /** Call a updatedatabase function and pass parameters*/
- }
- }
- break;
- case 4:
- System.out.println("Logout");/**display message*/
- break;
- }
- }while(menu != 4);
- }
- }
- else{
- System.out.println("Wrong password"); /**display message*/
- }
- }
- }catch(NullPointerException e){
- System.out.println("Account doexnt exist");/**display message*/
- }
- // enter login details check database new menu depends on user type (admin/standard)
- break;
- case 3:
- System.out.println("Closing Application");/**display message*/
- break;
- }
- }while(menu != 3);
- }
- }
- public static boolean isDbConnected() {
- String dbpath ="jdbc:mysql://localhost:3306/gradedunit2?autoReconnect=true&useSSL=false"; /** Creating a string called dbpath and setting its value to my database path. I will use it later to connect to my database */
- String dbid = "root"; /** Creating a string called dbit setting its value to root. I will use this variable each time i connect to database*/
- String dbpassword = "1234"; /** Creating a string called dbpassword setting its value to 1234. I will use this variable each time i connect to database*/
- final String CHECK_SQL_QUERY = "SELECT 1";
- boolean isConnected = false;
- try {/**start try block*/
- Connection db = null;
- db = DriverManager.getConnection(dbpath,dbid,dbpassword);
- final PreparedStatement statement = db.prepareStatement(CHECK_SQL_QUERY);
- isConnected = true;
- } catch (SQLException | NullPointerException e) {/**catch errors*/
- // handle SQL error here!
- }
- return isConnected;
- }
- public static String SetFormat(String s){
- /**im using this function to properly display statement*/
- int length = s.length( );
- while(length != 15){
- s = " "+s;
- length = s.length();
- }
- return s;
- /**@return s*/
- }
- public static String ToUpperCase(String s){
- /**it takes the string and sets the first letter of string to capital letter*/
- String ss = s; /** Create new variable called s which is equal to title*/
- ss = ss.substring(0,1).toUpperCase() + ss.substring(1).toLowerCase();/** setting first letter of s (index 0) to upper case and rest of them to lower*/
- s = ss; /** set s equal to ss */
- return s; /** @return s*/
- }
- public static void updatedatabase(String dbpath, String dbid,String dbpassword,String sqlcommand){
- /**im using this function multiple times to update database*/
- Connection conn5 = null;
- Statement stmt5 = null;
- try /**start try block*/
- {
- conn5 = DriverManager.getConnection(dbpath,dbid,dbpassword);
- stmt5 = conn5.createStatement();
- stmt5.execute(sqlcommand);
- } catch (Exception d) {/**catch errors*/
- d.printStackTrace();
- }finally {
- try { /**start try block*/
- stmt5.close();
- conn5.close();
- } catch (Exception e){} /**catch errors*/
- }
- }
- public static ArrayList readdatabase(String dbpath, String dbid,String dbpassword,String sqlcommand){
- /** Function that will return a arraylist with results from query if query returns null then at the first index there will be a text "NotFound"
- */
- Connection conn = null;
- Statement stmt = null;
- ResultSet res = null;
- ArrayList <String> dbresult = new ArrayList<String>();
- ArrayList <String> colname = new ArrayList<String>();
- try {/**start try block*/
- Class.forName("com.mysql.jdbc.Driver");
- conn = DriverManager.getConnection(dbpath,dbid,dbpassword);
- stmt = conn.createStatement();
- res = stmt.executeQuery(sqlcommand);
- ResultSetMetaData rsmd = res.getMetaData();
- int noofcolumns = rsmd.getColumnCount();
- for(int i = 1 ; i < noofcolumns+1; i++){ // loop getting column names and saving them to arraylist(unknown number or columns)
- String s = rsmd.getColumnName(i);
- colname.add(s);
- }
- while(res.next()){/** if rows2(return from sql statement) is NOT empty then loop */
- for(int i = 0 ; i < noofcolumns; i++){ // loop saving results to arraylist
- dbresult.add(res.getString(colname.get(i)));
- }
- // dbresult.add(Integer.toString(noofcolumns));
- }
- if(!res.next()){
- dbresult.add("NotFound");
- }
- }catch (SQLException ex) {
- System.out.println("SQLException: " + ex.getMessage());
- System.out.println("VendorError: " + ex.getErrorCode());
- } catch (ClassNotFoundException e) { /**catch errors*/
- e.printStackTrace();
- } finally {
- try { /**start try block*/
- res.close();
- stmt.close();
- conn.close();
- } catch (Exception e){}/**catch errors*/
- }
- return dbresult;
- /**@return dbresult*/
- }
- // later : make sure that all reads from database are made throught above class with returns result set!
- }
- ////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////
- /** Radoslaw Burkacki
- * 29/05/2016
- * Account class
- * This class is a blue print for Account objects */
- public class Account {
- private String Password; /** Creating new variable of String type called Password */
- private int AccountNumber; /** Creating new variable of int type called AccountNumber */
- private int SortCode; /** Creating new variable of int type called SortCode */
- private double Balance; /** Creating new variable of double type called Balance */
- private String AccountType; /** Creating new variable of String type called AccountType */
- /** All of above variables are private due to encapsulation which I am using */
- public Account(String password, int accountnumber, int sortcode, String accounttype) {
- /** Constructor that is expecting variables to be passed when object created
- * @param password
- * @param accountnumber
- * @param sortcode
- * @param accounttype
- * */
- this.Password = password; /**set variable password equal to password(was passed when called object) */
- this.AccountNumber = accountnumber; /**set variable AccountNumber equal to accountnumber(was passed when called object) */
- this.SortCode = sortcode; /**set variable SortCode equal to sortcode(was passed when called object) */
- this.Balance = 0; /**set variable Balance equal 0(it will be overwritten by premium or standard)*/
- this.AccountType = accounttype; /**set variable AccountType equal to accounttype(was passed when called object) */
- }
- /**
- * Setters
- *
- * @param password
- */
- public void setPassword(String password){
- Password = password;
- }
- /**
- * @param accountnumber
- */
- public void setAccountNumber(int accountnumber){
- AccountNumber = accountnumber;
- }
- /**
- * @param sortcode
- */
- public void setSortCode(int sortcode){
- SortCode = sortcode;
- }
- /**
- * @param balance
- */
- public void setBalance(double balance){
- Balance = balance;
- }
- /**
- * @param accounttype
- */
- public void setAccountType(String accounttype){
- AccountType = accounttype;
- }
- /**
- * Getters
- *
- * @return Password
- */
- String getPassword(){
- return Password;
- }
- /**@return AccountNumber */
- int getAccountNumber(){
- return AccountNumber;
- }
- /**@return SortCode */
- int getSortCode(){
- return SortCode;
- }
- /**@return Balance */
- double getBalance(){
- return Balance;
- }
- /**@return AccountType */
- String getAccountType(){
- return AccountType;
- }
- }
- ////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////
- /** Radoslaw Burkacki
- * 29/05/2016
- * Account class
- * This class is a blue print for Customers objects */
- public class Customer {
- private String Title; /** Creating new variable of String type called Title */
- private String FName; /** Creating new variable of String type called FName */
- private String LName; /** Creating new variable of String type called LName */
- private String City; /** Creating new variable of String type called City */
- private String PostCode; /** Creating new variable of String type called PostCode */
- private String Address; /** Creating new variable of String type called Address */
- /** All of above variables are private due to encapsulation which I am using */
- public Customer(String title, String fname, String lname, String city, String postcode, String address) { /** Constructor that is expecting variables to be passed when object created
- *@param title
- *@param fname
- *@param lname
- *@param city
- *@param postcode
- *@param address
- */
- this.Title = title; /**set variable Title equal to title(was passed when called object) */
- this.FName = fname; /**set variable FName equal to fname(was passed when called object) */
- this.LName = lname; /**set variable LName equal to lname(was passed when called object) */
- this.City = city; /**set variable City equal to city(was passed when called object) */
- this.PostCode = postcode; /**set variable PostCode equal to postcode(was passed when called object) */
- this.Address = address; /**set variable Address equal to address(was passed when called object) */
- }
- /**
- * Setters
- * @param title String that was passed when object was created(title)
- */
- public void setTitle(String title){
- Title = title;
- }
- /**
- * @param fname String that was passed when object was created(first name)
- */
- public void setFName(String fname){
- FName = fname;
- }
- /**
- * @param lname String that was passed when object was created(last name)
- */
- public void setLName(String lname){
- LName = lname;
- }
- /**
- * @param city String that was passed when object was created(city)
- */
- public void setCity(String city){
- City = city;
- }
- /**
- * @param postcode String that was passed when object was created(postcode)
- */
- public void setPostCode(String postcode){
- PostCode = postcode;
- }
- /**
- * @param address String that was passed when object was created(address)
- */
- public void setAddress(String address){
- Address = address;
- }
- /**
- * Getters
- * @return Title
- */
- public String getTitle(){
- return Title;
- }
- /**
- * @return FName
- */
- public String getFName(){
- return FName;
- }
- /**
- * @return LName
- */
- public String getLName(){
- return LName;
- }
- /**
- * @return City
- */
- public String getCity(){
- return City;
- }
- /**
- * @return PostCode
- */
- public String getPostCode(){
- return PostCode;
- }
- /**
- * @return Address
- */
- public String getAddress(){
- return Address;
- }
- }
- ////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////
- /** Radoslaw Burkacki
- * 29/05/2016
- * Sub class of Account
- * This class is used to set balance to -5.00 */
- public class Premium extends Account {
- public Premium(String password, int accountnumber, int sortcode, String accounttype) {
- super(password, accountnumber, sortcode, accounttype);
- super.setBalance(-5.00);
- }
- }
- ////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////
- /** Radoslaw Burkacki
- * 29/05/2016
- * Sub class of Account
- * This class is used to set balance to 0.00 */
- public class Standard extends Account{
- public Standard(String password, int accountnumber, int sortcode, String accounttype) {
- super(password, accountnumber, sortcode, accounttype);
- super.setBalance(0.00);
- }
- }
Add Comment
Please, Sign In to add comment