diff --git a/AccountIE/bin/com/demo/bean/Account.class b/AccountIE/bin/com/demo/bean/Account.class new file mode 100644 index 00000000..0e0552be Binary files /dev/null and b/AccountIE/bin/com/demo/bean/Account.class differ diff --git a/AccountIE/bin/com/demo/bean/Current.class b/AccountIE/bin/com/demo/bean/Current.class new file mode 100644 index 00000000..92121b63 Binary files /dev/null and b/AccountIE/bin/com/demo/bean/Current.class differ diff --git a/AccountIE/bin/com/demo/bean/Savings.class b/AccountIE/bin/com/demo/bean/Savings.class new file mode 100644 index 00000000..3ba285cf Binary files /dev/null and b/AccountIE/bin/com/demo/bean/Savings.class differ diff --git a/AccountIE/bin/com/demo/dao/AccountDao.class b/AccountIE/bin/com/demo/dao/AccountDao.class new file mode 100644 index 00000000..ba3efdc4 Binary files /dev/null and b/AccountIE/bin/com/demo/dao/AccountDao.class differ diff --git a/AccountIE/bin/com/demo/dao/AccountDaoImp.class b/AccountIE/bin/com/demo/dao/AccountDaoImp.class new file mode 100644 index 00000000..ac570265 Binary files /dev/null and b/AccountIE/bin/com/demo/dao/AccountDaoImp.class differ diff --git a/AccountIE/bin/com/demo/exception/AccountNotFoundException.class b/AccountIE/bin/com/demo/exception/AccountNotFoundException.class new file mode 100644 index 00000000..cd6343b8 Binary files /dev/null and b/AccountIE/bin/com/demo/exception/AccountNotFoundException.class differ diff --git a/AccountIE/bin/com/demo/service/AccService.class b/AccountIE/bin/com/demo/service/AccService.class new file mode 100644 index 00000000..a6ac2f4a Binary files /dev/null and b/AccountIE/bin/com/demo/service/AccService.class differ diff --git a/AccountIE/bin/com/demo/service/AccServiceImp.class b/AccountIE/bin/com/demo/service/AccServiceImp.class new file mode 100644 index 00000000..f00e9103 Binary files /dev/null and b/AccountIE/bin/com/demo/service/AccServiceImp.class differ diff --git a/AccountIE/bin/com/demo/test/AccountTest.class b/AccountIE/bin/com/demo/test/AccountTest.class new file mode 100644 index 00000000..0928a148 Binary files /dev/null and b/AccountIE/bin/com/demo/test/AccountTest.class differ diff --git a/AccountIE/src/com/demo/bean/Account.java b/AccountIE/src/com/demo/bean/Account.java new file mode 100644 index 00000000..3974b323 --- /dev/null +++ b/AccountIE/src/com/demo/bean/Account.java @@ -0,0 +1,86 @@ +package com.demo.bean; +import java.util.Date; + +abstract public class Account { + static { + + cnt = 0; + } + public static int cnt; + private int perId; + private String pName; + private int pin; + private Date dOp; + protected double balance; + private String accType; + + //default constructor + public Account() { + + perId = 0; + pName = null; + int pin = 0; + dOp = null; + balance = 0.0; + String accType = null; + } + + //parameterized constructor + public Account(String pName, int pin, Date dOp, double bal, String aType) { + this.perId = ++cnt ; + this.pName = pName; + this.pin = pin; + this.dOp = dOp; + this.balance = bal; + this.accType = aType; + } + //setter and getter methods + public int getId() { + return this.perId; + } + + public void setId(int perId) { + this.perId = perId; + } + + public void setBal (double bal) { + this.balance = bal; + } + + public double getBal() { + return this.balance; + } + + public String getpName() { + return this.pName; + } + + public void setpName(String pName) { + this.pName = pName; + } + + public int getPin() { + return this.pin; + } + + public void setPin(int pin) { + this.pin = pin; + } + + public String getAcType() { + return this.accType; + } + + //function for deposit operation + public void deposit(double amt) { + balance = balance + amt; + } + abstract public void withdraw(double amt); + + @Override + public String toString() { + return "Id: "+perId +"\nName: " +pName+ "\nDate of opening :"+ dOp+"\nbalance: "+balance; + } + + +} diff --git a/AccountIE/src/com/demo/bean/Current.java b/AccountIE/src/com/demo/bean/Current.java new file mode 100644 index 00000000..6da1083a --- /dev/null +++ b/AccountIE/src/com/demo/bean/Current.java @@ -0,0 +1,37 @@ +package com.demo.bean; + +import java.util.Date; + +public class Current extends Account { + private int nOfTxn = 3; + final static private float intRate = 2.4f; + + //default constructor + public Current() { + } + + //parameterized constructor + public Current(String pName, int pin, Date dOp, double bal, String aType) { + super(pName,pin,dOp,bal,aType); + + } + + //calculate interest + public double interest(double bal) { + return bal*intRate; + } + + //function for withdraw operation + public void withdraw(double amt) { + if(!(balance <=0)) { + balance = balance - amt; + } + else { + System.out.println("Less balance"); + } + } + + public String toString() { + return super.toString() + "\n"; + } +} diff --git a/AccountIE/src/com/demo/bean/Savings.java b/AccountIE/src/com/demo/bean/Savings.java new file mode 100644 index 00000000..93385be8 --- /dev/null +++ b/AccountIE/src/com/demo/bean/Savings.java @@ -0,0 +1,42 @@ +package com.demo.bean; + +import java.util.Date; + +public class Savings extends Account { + + private int cheqBn; + private float intRate = 3.5f; + + // default constructor + public Savings() { + cheqBn = 0; + } + + // Parameterized constructor + public Savings(String pName, int pin, Date dOp, double bal, String aType, int cheqBn) { + super(pName, pin, dOp, bal, aType); + this.cheqBn = cheqBn; + } + + // calculate interest + public double interest(double bal) { + if (bal > 50000) { + return bal * intRate + 0.02 * bal; + } else { + return bal * intRate; + } + } + + // function for withdraw operation + public void withdraw(double amt) { + if (balance - 10000 >= amt) { + balance = balance - amt; + } else { + System.out.println("Less balance"); + } + } + + public String toString() { + return super.toString() + "\ncheque book number: " + cheqBn; + } +} diff --git a/AccountIE/src/com/demo/dao/AccountDao.java b/AccountIE/src/com/demo/dao/AccountDao.java new file mode 100644 index 00000000..4d58d6c5 --- /dev/null +++ b/AccountIE/src/com/demo/dao/AccountDao.java @@ -0,0 +1,23 @@ +package com.demo.dao; + +import com.demo.bean.Account; +import com.demo.exception.AccountNotFoundException; + +public interface AccountDao { + + void acceptData(Account a); + + Account searchById(int id) throws AccountNotFoundException; + + boolean pinVerify(int pin, int id) throws AccountNotFoundException; + + void depositAmt(int id, double amt, Account ob); + + void tranAmt(Account src,Account des, double amt); + + void changePin(int id, int newPin, Account ob); + + double checkBal(int id, Account ob); + + +} diff --git a/AccountIE/src/com/demo/dao/AccountDaoImp.java b/AccountIE/src/com/demo/dao/AccountDaoImp.java new file mode 100644 index 00000000..29897dde --- /dev/null +++ b/AccountIE/src/com/demo/dao/AccountDaoImp.java @@ -0,0 +1,77 @@ +package com.demo.dao; + +import com.demo.bean.Account; +import com.demo.exception.AccountNotFoundException; + +public class AccountDaoImp implements AccountDao { + static { + acc = new Account[10]; + cnt = 0; + } + + static Account[] acc; + static int cnt; + + @Override + public void acceptData(Account a) { + // TODO Auto-generated method stub + acc[cnt] = a; + cnt++; + } + + @Override + public Account searchById(int id) throws AccountNotFoundException { + // TODO Auto-generated method stub + for (Account a : acc) { + if(a!=null) { + if (a.getId() == id) { + return a; + } + }else { + break; + } + + } + throw new AccountNotFoundException ("Account not found"); + } + + @Override + public boolean pinVerify(int pin, int id) throws AccountNotFoundException { + // TODO Auto-generated method stub + Account a = searchById(id); + if (a != null) { + if (pin == a.getPin()) { + return true; + } + } + return false; + } + + @Override + public void depositAmt(int id, double amt, Account ob) { + // TODO Auto-generated method stub + ob.deposit(amt); + + } + + @Override + public void tranAmt(Account src, Account des, double amt) { + // TODO Auto-generated method stub + src.setBal(src.getBal() - amt); + des.setBal(des.getBal() + amt); + } + + @Override + public void changePin(int id, int newPin, Account ob) { + // TODO Auto-generated method stub + ob.setPin(newPin); + + } + + @Override + public double checkBal(int id, Account ob) { + // TODO Auto-generated method stub + return ob.getBal(); + } + +} diff --git a/AccountIE/src/com/demo/exception/AccountNotFoundException.java b/AccountIE/src/com/demo/exception/AccountNotFoundException.java new file mode 100644 index 00000000..e8d1ec37 --- /dev/null +++ b/AccountIE/src/com/demo/exception/AccountNotFoundException.java @@ -0,0 +1,7 @@ +package com.demo.exception; + +public class AccountNotFoundException extends Exception{ + public AccountNotFoundException(String msg) { + super(msg); + } +} diff --git a/AccountIE/src/com/demo/service/AccService.java b/AccountIE/src/com/demo/service/AccService.java new file mode 100644 index 00000000..a96f89c9 --- /dev/null +++ b/AccountIE/src/com/demo/service/AccService.java @@ -0,0 +1,26 @@ +package com.demo.service; + +import com.demo.bean.Account; +import com.demo.exception.AccountNotFoundException; + +public interface AccService { + + void acceptAccData(String schoice); + + Account searchById(int id) throws AccountNotFoundException; + + boolean pinVerify(int pin, int id); + + void withdrawAmt(int id, double amt) throws AccountNotFoundException; + + void depositAmt(int id, double amt) throws AccountNotFoundException; + + void tranAmt(int id, int id2, double amt) throws AccountNotFoundException; + + void changePin(int id, int newPin) throws AccountNotFoundException; + + double checkBal(int id) throws AccountNotFoundException; + + Account dispById(int id) throws AccountNotFoundException; + +} diff --git a/AccountIE/src/com/demo/service/AccServiceImp.java b/AccountIE/src/com/demo/service/AccServiceImp.java new file mode 100644 index 00000000..a8b40f17 --- /dev/null +++ b/AccountIE/src/com/demo/service/AccServiceImp.java @@ -0,0 +1,123 @@ +package com.demo.service; + +import java.util.Date; +import java.util.Scanner; + +import com.demo.bean.Account; +import com.demo.bean.Current; +import com.demo.bean.Savings; +import com.demo.dao.AccountDao; +import com.demo.dao.AccountDaoImp; +import com.demo.exception.AccountNotFoundException; + +public class AccServiceImp implements AccService { + static { + sc = new Scanner(System.in); + } + static Scanner sc; + private AccountDao accDao; + + public AccServiceImp() { + this.accDao = new AccountDaoImp(); + } + + @Override + public void acceptAccData(String type) { + Account acc = null; + System.out.println("Enter account holder's name: "); + String name = sc.next(); + System.out.println("enter the pin"); + int pin = sc.nextInt(); + System.out.println("enter the cheque book number"); + int chqBn = sc.nextInt(); + System.out.println("Enter balance: "); + double bal = sc.nextDouble(); + Date dOp = new Date(); + if (type.equals("sav")) { + acc = new Savings(name, pin, dOp, bal, type, chqBn); + accDao.acceptData(acc); + } else { + acc = new Current(name, pin, dOp, bal, type); + accDao.acceptData(acc); + } + } + + @Override + public boolean pinVerify(int pin, int id) { + // TODO Auto-generated method stub + try { + return accDao.pinVerify(pin, id); + } catch (AccountNotFoundException e) { + // TODO Auto-generated catch block + System.out.println(e.getMessage()); + return false; + } + } + + @Override + public Account searchById(int id) throws AccountNotFoundException { + // TODO Auto-generated method stub + return accDao.searchById(id); + } + + @Override + public void withdrawAmt(int id, double amt) throws AccountNotFoundException { + // TODO Auto-generated method stub + Account a = accDao.searchById(id); + if(a!=null) { + a.withdraw(amt); + } + + } + + @Override + public void depositAmt(int id, double amt) throws AccountNotFoundException { + // TODO Auto-generated method stub + Account a = accDao.searchById(id); + if(a!=null) { + accDao.depositAmt(id, amt, a); + } + + } + + @Override + public void tranAmt(int id, int id2, double amt) throws AccountNotFoundException { + // TODO Auto-generated method stub + Account a1 = accDao.searchById(id); + Account a2 = accDao.searchById(id2); + if(a1!=null && a2 != null) { + accDao.tranAmt(a1, a2, amt); + } + } + + @Override + public void changePin(int id, int newPin) throws AccountNotFoundException { + // TODO Auto-generated method stub + Account a = accDao.searchById(id); + if(a!=null) { + accDao.changePin(id, newPin, a); + } + } + + @Override + public double checkBal(int id) throws AccountNotFoundException { + // TODO Auto-generated method stub + Account a = accDao.searchById(id); + if(a!=null) { + return accDao.checkBal(id, a); + }else { + return 0.0; + } + + } + + @Override + public Account dispById(int id) throws AccountNotFoundException { + // TODO Auto-generated method stub + Account a = accDao.searchById(id); + return a; + } + + + +} diff --git a/AccountIE/src/com/demo/test/AccountTest.java b/AccountIE/src/com/demo/test/AccountTest.java new file mode 100644 index 00000000..abe2feae --- /dev/null +++ b/AccountIE/src/com/demo/test/AccountTest.java @@ -0,0 +1,148 @@ +package com.demo.test; + +import java.util.Date; +import java.util.Scanner; + +import com.demo.bean.Account; +import com.demo.bean.Current; +import com.demo.bean.Savings; +import com.demo.exception.AccountNotFoundException; +import com.demo.service.AccService; +import com.demo.service.AccServiceImp; + +public class AccountTest { + + public static void main(String[] args) { + // TODO Auto-generated method stub + + Scanner sc = new Scanner(System.in); + AccService a = new AccServiceImp(); + int choice = 0; + String schoice = null; + do { + System.out.println("1.Add new account"); + System.out.println("2.withdraw"); + System.out.println("3.deposit"); + System.out.println("4.transfer fund"); + System.out.println("5.change pin"); + System.out.println("6.check balance"); + System.out.println("7.display by id"); + System.out.println("8.exit"); + choice = sc.nextInt(); + switch (choice) { + case 1: + System.out.println("type of account, sav/cur?"); + schoice = sc.next(); + a.acceptAccData(schoice); + + break; + case 2: + System.out.println("enter the per id"); + int id = sc.nextInt(); + System.out.println("enter the amount to be withdrawn"); + double amt = sc.nextDouble(); + System.out.println("enter the account pin"); + int pin = sc.nextInt(); + try { + if (a.pinVerify(pin, id)) { + a.withdrawAmt(id, amt); + } else { + System.out.println("incorrect pin entered"); + } + } catch (AccountNotFoundException e) { + // TODO Auto-generated catch block + System.out.println(e.getMessage()); + // e.printStackTrace(); + } + break; + case 3: + System.out.println("enter the per id"); + id = sc.nextInt(); + System.out.println("enter the amount to be deposited"); + amt = sc.nextDouble(); + System.out.println("enter the account pin"); + pin = sc.nextInt(); + try { + if (a.pinVerify(pin, id)) { + a.depositAmt(id, amt); + } else { + System.out.println("incorrect pin entered"); + } + }catch(AccountNotFoundException e) { + System.out.println(e.getMessage()); + } + + break; + case 4: + System.out.println("enter the id of the debit account"); + id = sc.nextInt(); + System.out.println("enter the account pin"); + pin = sc.nextInt(); + try { + if (a.pinVerify(pin, id)) { + System.out.println("enter the id of the credit account"); + int id2 = sc.nextInt(); + System.out.println("enter the amount to be transferred"); + amt = sc.nextDouble(); + a.tranAmt(id, id2, amt); + } else { + System.out.println("incorrect pin entered"); + } + }catch(AccountNotFoundException e) { + System.out.println(e.getMessage()); + } + + break; + case 5: + System.out.println("enter the id of the debit account"); + id = sc.nextInt(); + System.out.println("enter the account pin"); + pin = sc.nextInt(); + try { + if (a.pinVerify(pin, id)) { + System.out.println("enter the new pin"); + int newPin = sc.nextInt(); + a.changePin(id, newPin); + } else { + System.out.println("incorrect pin entered"); + } + }catch(AccountNotFoundException e) { + System.out.println(e.getMessage()); + } + + case 6: + System.out.println("enter the id of the account"); + id = sc.nextInt(); + System.out.println("enter the account pin"); + pin = sc.nextInt(); + try { + double bal = 0.0; + if (a.pinVerify(pin, id)) { + bal = a.checkBal(id); + System.out.println("The balance is :" + bal); + } + }catch(AccountNotFoundException e) { + System.out.println(e.getMessage()); + } + + break; + case 7: + System.out.println("enter the id of the account"); + id = sc.nextInt(); + try { + Account q = a.dispById(id); + System.out.println(q); + }catch(AccountNotFoundException e) { + System.out.println(e.getMessage()); + } + + break; + case 8: + System.exit(0); + } + + } while (choice != 8); + sc.close(); + } + +} diff --git a/MyAccountInfo_assignment/.classpath b/MyAccountInfo_assignment/.classpath new file mode 100644 index 00000000..f00af9b4 --- /dev/null +++ b/MyAccountInfo_assignment/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/MyAccountInfo_assignment/.project b/MyAccountInfo_assignment/.project new file mode 100644 index 00000000..84d33c1b --- /dev/null +++ b/MyAccountInfo_assignment/.project @@ -0,0 +1,17 @@ + + + MyAccountInfo + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/MyAccountInfo_assignment/bin/com/demo/bean/Account.class b/MyAccountInfo_assignment/bin/com/demo/bean/Account.class new file mode 100644 index 00000000..1964fb2b Binary files /dev/null and b/MyAccountInfo_assignment/bin/com/demo/bean/Account.class differ diff --git a/MyAccountInfo_assignment/bin/com/demo/service/AccountService.class b/MyAccountInfo_assignment/bin/com/demo/service/AccountService.class new file mode 100644 index 00000000..8189e528 Binary files /dev/null and b/MyAccountInfo_assignment/bin/com/demo/service/AccountService.class differ diff --git a/MyAccountInfo_assignment/bin/com/demo/test/TestAccountClass.class b/MyAccountInfo_assignment/bin/com/demo/test/TestAccountClass.class new file mode 100644 index 00000000..735c3bd1 Binary files /dev/null and b/MyAccountInfo_assignment/bin/com/demo/test/TestAccountClass.class differ diff --git a/MyAccountInfo_assignment/src/com/demo/bean/Account.java b/MyAccountInfo_assignment/src/com/demo/bean/Account.java new file mode 100644 index 00000000..f4f1865f --- /dev/null +++ b/MyAccountInfo_assignment/src/com/demo/bean/Account.java @@ -0,0 +1,78 @@ +package com.demo.bean; +import java.util.Date; + +public class Account { + static { + //ifsc = "QWER"; + cnt = 0; + } + //public static String ifsc; + private static int cnt; + private int perId; + private String pName; + private String typeOfAcc; + private Date dOp; + private double balance; + + //default constructor + public Account() { + perId = 0; + pName = null; + typeOfAcc = null; + dOp = null; + + } + + //parameterized constructor + public Account(String pName, String typeOfAcc, Date dOp, double bal) { + this.perId = cnt++ ; + this.pName = pName; + this.typeOfAcc = typeOfAcc; + this.dOp = dOp; + this.balance = bal; + } + //setter and getter methods + public int getId() { + return this.perId; + } + + public void setId(int perId) { + this.perId = perId; + } + + public void setBal (double bal) { + this.balance = bal; + } + + public double getBal() { + return this.balance; + } + + public String getpName() { + return this.pName; + } + + public void setpName(String pName) { + this.pName = pName; + } + + //function for deposit operation + public void deposit(double amt) { + balance = balance + amt; + } + + //function for withdraw operation + public void withdraw(double amt) { + if(balance-10000 >= amt) { + balance = balance - amt; + } + else { + System.out.println("Less balance"); + } + } + + @Override + public String toString() { + return "Id: "+perId +"\nName: " +pName + "\nType of account:"+ typeOfAcc + "\nDate of opening :"+ dOp+"\nbalance: "+balance; + } +} diff --git a/MyAccountInfo_assignment/src/com/demo/service/AccountService.java b/MyAccountInfo_assignment/src/com/demo/service/AccountService.java new file mode 100644 index 00000000..62c874c9 --- /dev/null +++ b/MyAccountInfo_assignment/src/com/demo/service/AccountService.java @@ -0,0 +1,102 @@ +package com.demo.service; + +import java.util.Scanner; +import com.demo.bean.Account; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class AccountService { + //public static SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); + public static Scanner sc = new Scanner(System.in); + + // function to accept account data + public static void acceptAccountData(Account[] acc) { + for (int i = 0; i < acc.length; i++) { + /* + * System.out.println("Enter account ID"); int id = sc.nextInt(); + */ + System.out.println("Enter account holder's name: "); + String name = sc.next(); + System.out.println("Enter type of account: "); + String acctype = sc.next(); + System.out.println("Enter balance: "); + double bal = sc.nextDouble(); + //System.out.println("Enter date of opening: "); + //String dt = sc.next(); + Date dOp = new Date(); + acc[i] = new Account(name, acctype, dOp, bal); + + } + + } + + // function to search by ID + public static int searchById(Account[] acc, int id) { + for (int i = 0; i < acc.length; i++) { + if (acc[i].getId() == id) { + return i; + } + } + return -1; + } + + // function to deposit amount + public static int depositAmt(Account[] acc, int id, double amt) { + int pos = searchById(acc, id); + if (pos != -1) { + acc[pos].deposit(amt); + System.out.println("New balance:" + acc[pos].getBal()); + return pos; + } else { + System.out.println("person not found"); + return -1; + } + } + + // function to withdraw amount + public static int withdrawAmt(Account[] acc, int id, double amt) { + + int pos = searchById(acc, id); + if (pos != -1) { + acc[pos].withdraw(amt); + System.out.println("New balance:" + acc[pos].getBal()); + return pos; + } else { + System.out.println("person not found"); + return -1; + } + + } + + // function to display account data + public static void displayData(Account[] acc) { + for (int i = 0; i < acc.length; i++) { + if (acc[i] != null) { + System.out.println(acc[i]); + } else { + break; + } + } + } + + public static int searchByName(Account[] a, String nm) { + // TODO Auto-generated method stub + for (int i = 0; i < a.length; i++) { + if (a[i].getpName().equals(nm)) { + return i; + } + } + return -1; + } + + // display account by ID + public static void dispById(Account[] a, int id) { + int pos = searchById(a, id); + if (pos != -1) { + System.out.println(a[pos]); + } else { + System.out.println("Account not found"); + } + } +} diff --git a/MyAccountInfo_assignment/src/com/demo/test/TestAccountClass.java b/MyAccountInfo_assignment/src/com/demo/test/TestAccountClass.java new file mode 100644 index 00000000..9b068044 --- /dev/null +++ b/MyAccountInfo_assignment/src/com/demo/test/TestAccountClass.java @@ -0,0 +1,67 @@ +package com.demo.test; + +import com.demo.bean.Account; +import com.demo.service.AccountService; +import java.util.Scanner; + +public class TestAccountClass { + + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner sc = new Scanner(System.in); + Account[] a = new Account[3]; + int choice = 0; + do { + System.out.println("1.add new person"); + System.out.println("2.search person by name"); + System.out.println("3.deposit amount"); + System.out.println("4.withdraw amount"); + System.out.println("5.display account by id"); + System.out.println("6.exit"); + choice = sc.nextInt(); + switch (choice) { + case 1: + AccountService.acceptAccountData(a); + break; + case 2: + System.out.println("enter the name to be searched"); + String nm = sc.next(); + int posn = AccountService.searchByName(a, nm); + if (posn != -1) { + System.out.println(a[posn]); + } else { + System.out.println("person not found"); + } + break; + case 3: + System.out.println("Enter the amount to be deposited: "); + double damt = sc.nextDouble(); + System.out.println("Enter the person ID: "); + int dId = sc.nextInt(); + AccountService.depositAmt(a, dId, damt); + break; + case 4: + System.out.println("Enter the amount to be withdrawn: "); + double wAmt = sc.nextDouble(); + System.out.println("Enter the person ID: "); + int wId = sc.nextInt(); + AccountService.withdrawAmt(a, wId, wAmt); + break; + case 5: + System.out.println("enter id to display data"); + int id = sc.nextInt(); + int pos = AccountService.searchById(a, id); + if (pos != -1) { + System.out.println(a[pos]); + } else { + System.out.println("person not found"); + } + break; + case 6: + System.exit(0); + } + } while (choice != 6); + sc.close(); + } + +} diff --git a/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/bin/com/demo/bean/Apparel.class b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/bin/com/demo/bean/Apparel.class new file mode 100644 index 00000000..6b64d874 Binary files /dev/null and b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/bin/com/demo/bean/Apparel.class differ diff --git a/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/bin/com/demo/bean/Electronics.class b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/bin/com/demo/bean/Electronics.class new file mode 100644 index 00000000..44840354 Binary files /dev/null and b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/bin/com/demo/bean/Electronics.class differ diff --git a/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/bin/com/demo/bean/Food.class b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/bin/com/demo/bean/Food.class new file mode 100644 index 00000000..fc21740c Binary files /dev/null and b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/bin/com/demo/bean/Food.class differ diff --git a/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/bin/com/demo/bean/Products.class b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/bin/com/demo/bean/Products.class new file mode 100644 index 00000000..73dc7e43 Binary files /dev/null and b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/bin/com/demo/bean/Products.class differ diff --git a/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/bin/com/demo/dao/ProdDao.class b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/bin/com/demo/dao/ProdDao.class new file mode 100644 index 00000000..977fd27a Binary files /dev/null and b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/bin/com/demo/dao/ProdDao.class differ diff --git a/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/bin/com/demo/dao/ProdDaoImpl.class b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/bin/com/demo/dao/ProdDaoImpl.class new file mode 100644 index 00000000..8bdcc733 Binary files /dev/null and b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/bin/com/demo/dao/ProdDaoImpl.class differ diff --git a/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/bin/com/demo/exception/InvalidProductException.class b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/bin/com/demo/exception/InvalidProductException.class new file mode 100644 index 00000000..acb2750b Binary files /dev/null and b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/bin/com/demo/exception/InvalidProductException.class differ diff --git a/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/bin/com/demo/service/ProdService.class b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/bin/com/demo/service/ProdService.class new file mode 100644 index 00000000..79d680db Binary files /dev/null and b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/bin/com/demo/service/ProdService.class differ diff --git a/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/bin/com/demo/service/ProdServiceImpl.class b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/bin/com/demo/service/ProdServiceImpl.class new file mode 100644 index 00000000..fb716892 Binary files /dev/null and b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/bin/com/demo/service/ProdServiceImpl.class differ diff --git a/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/bin/com/demo/test/ProdTest.class b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/bin/com/demo/test/ProdTest.class new file mode 100644 index 00000000..fb3850b9 Binary files /dev/null and b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/bin/com/demo/test/ProdTest.class differ diff --git a/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/src/com/demo/bean/Apparel.java b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/src/com/demo/bean/Apparel.java new file mode 100644 index 00000000..b1ada180 --- /dev/null +++ b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/src/com/demo/bean/Apparel.java @@ -0,0 +1,46 @@ +package com.demo.bean; + +public class Apparel extends Products{ + private int size; + private String material; + + //default constructor + public Apparel() { + super(); + this.size =0; + this.material=null; + } + + //parameterised constructor + public Apparel(int itmCode, String itmName, double price, int qty,String pType,int size, String material) { + super(itmCode,itmName,price,qty,pType); + this.size = size; + this.material = material; + } + + //generate getter and setter methods + public int getSize() { + return size; + } + + public void setSize(int size) { + this.size = size; + } + + public String getMaterial() { + return material; + } + + public void setMaterial(String material) { + this.material = material; + } + + @Override + public String toString() { + return super.toString()+"Apparel [size=" + size + ", material=" + material + "]"; + } + + + + +} diff --git a/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/src/com/demo/bean/Electronics.java b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/src/com/demo/bean/Electronics.java new file mode 100644 index 00000000..8aa8050c --- /dev/null +++ b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/src/com/demo/bean/Electronics.java @@ -0,0 +1,34 @@ +package com.demo.bean; + +public class Electronics extends Products { + private int warranty; + + //parameterised constructor + public Electronics() { + super(); + } + + //default constructor + public Electronics(int itmCode, String itmName, double price, int qty,String pType,int warranty) { + super(itmCode,itmName,price,qty,pType); + this.warranty = warranty; + } + + //getter and setter methods + public int getWarranty() { + return warranty; + } + + public void setWarranty(int warranty) { + this.warranty = warranty; + } + + @Override + public String toString() { + return super.toString()+"Electronics [warranty=" + warranty + "]"; + } + + + + +} diff --git a/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/src/com/demo/bean/Food.java b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/src/com/demo/bean/Food.java new file mode 100644 index 00000000..8080fd24 --- /dev/null +++ b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/src/com/demo/bean/Food.java @@ -0,0 +1,57 @@ +package com.demo.bean; + +import java.util.Date; + +public class Food extends Products { + private Date dOfManf; + private Date dOfExp; + private boolean veg; + + + // default constructor + public Food() { + super(); + } + + // parameterised constructor + public Food(int itmCode, String itmName, double price, int qty,String pType,Date dOfManf, Date dOfExp, boolean veg) { + super(itmCode,itmName,price,qty,pType); + this.dOfManf = dOfManf; + this.dOfExp = dOfExp; + this.veg = veg; + } + + //setter and getter methods + public Date getdOfManf() { + return dOfManf; + } + + public void setdOfManf(Date dOfManf) { + this.dOfManf = dOfManf; + } + + public Date getdOfExp() { + return dOfExp; + } + + public void setdOfExp(Date dOfExp) { + this.dOfExp = dOfExp; + } + + public boolean isVeg() { + return veg; + } + + public void setVeg(boolean veg) { + this.veg = veg; + } + + //tostring method + @Override + public String toString() { + return super.toString()+"Food [dOfManf=" + dOfManf + ", dOfExp=" + dOfExp + ", veg=" + veg + "]"; + } + + + +} diff --git a/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/src/com/demo/bean/Products.java b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/src/com/demo/bean/Products.java new file mode 100644 index 00000000..f0d1f14d --- /dev/null +++ b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/src/com/demo/bean/Products.java @@ -0,0 +1,89 @@ +package com.demo.bean; + +//product class described as base class +public class Products implements Comparable { + private int itmCode; + private String itmName; + private double price; + private int qty; + private String pType; + + // default constructor + public Products() { + super(); + this.itmCode = 0; + this.itmName = null; + this.price = 0; + this.qty = 0; + this.pType = null; + } + + // parameterised constructor + public Products(int itmCode, String itmName, double price, int qty, String pType) { + super(); + this.itmCode = itmCode; + this.itmName = itmName; + this.price = price; + this.qty = qty; + this.pType = pType; + } + + // getter and setter methods for variables + public int getItmCode() { + return itmCode; + } + + public void setItmCode(int itmCode) { + this.itmCode = itmCode; + } + + public String getItmName() { + return itmName; + } + + public void setItmName(String itmName) { + this.itmName = itmName; + } + + public double getPrice() { + return price; + } + + public void setPrice(double price) { + this.price = price; + } + + public int getQty() { + return qty; + } + + public void setQty(int qty) { + this.qty = qty; + } + + public String getpType() { + return pType; + } + + public void setpType(String pType) { + this.pType = pType; + } + + // tostring method to print the values + @Override + public String toString() { + return "Products [itmCode=" + itmCode + ", itmName=" + itmName + ", price=" + price + ", qty=" + qty + + ", pType=" + pType + "]"; + } + //compareto method for treeset to sort on quantities + @Override + public int compareTo(Object o) { + if(this.qty > ((Products)o).qty) + return -1; + if(this.qty < ((Products)o).qty) + return 1; + else + return 0; + } + +} diff --git a/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/src/com/demo/dao/ProdDao.java b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/src/com/demo/dao/ProdDao.java new file mode 100644 index 00000000..a3900d03 --- /dev/null +++ b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/src/com/demo/dao/ProdDao.java @@ -0,0 +1,13 @@ +package com.demo.dao; + +import java.util.Set; + +import com.demo.bean.Products; + +public interface ProdDao { + + void addProduct(Products prod, String type); + + Set getProds(String type); + +} diff --git a/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/src/com/demo/dao/ProdDaoImpl.java b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/src/com/demo/dao/ProdDaoImpl.java new file mode 100644 index 00000000..90dbea6c --- /dev/null +++ b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/src/com/demo/dao/ProdDaoImpl.java @@ -0,0 +1,42 @@ +package com.demo.dao; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; + +import com.demo.bean.Products; + +public class ProdDaoImpl implements ProdDao { + static { + eSet = new TreeSet<>(); + fSet = new TreeSet<>(); + aSet = new TreeSet<>(); + } + static Set eSet; + static Set fSet; + static Set aSet; + + //dao layer function to add products + @Override + public void addProduct(Products prod, String type) { + // TODO Auto-generated method stub + if(type.equals("food")) { + fSet.add(prod); + }else if(type.equals("apparel")) { + aSet.add(prod); + }else { + eSet.add(prod); + } + } + //function to get 3 produ + @Override + public Set getProds(String type) { + List list = new ArrayList<>(); + if(type.equals("food")) { + + } + } + + +} diff --git a/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/src/com/demo/exception/InvalidProductException.java b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/src/com/demo/exception/InvalidProductException.java new file mode 100644 index 00000000..8f63f605 --- /dev/null +++ b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/src/com/demo/exception/InvalidProductException.java @@ -0,0 +1,7 @@ +package com.demo.exception; + +public class InvalidProductException extends Exception { + public InvalidProductException(String msg) { + super(msg); + } +} diff --git a/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/src/com/demo/service/ProdService.java b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/src/com/demo/service/ProdService.java new file mode 100644 index 00000000..ad36b632 --- /dev/null +++ b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/src/com/demo/service/ProdService.java @@ -0,0 +1,9 @@ +package com.demo.service; + +public interface ProdService { + + void addProduct(String type); + + void getProd(String ptype); + +} diff --git a/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/src/com/demo/service/ProdServiceImpl.java b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/src/com/demo/service/ProdServiceImpl.java new file mode 100644 index 00000000..b3244903 --- /dev/null +++ b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/src/com/demo/service/ProdServiceImpl.java @@ -0,0 +1,85 @@ +package com.demo.service; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Scanner; +import java.util.Set; + +import com.demo.bean.Apparel; +import com.demo.bean.Electronics; +import com.demo.bean.Food; +import com.demo.bean.Products; +import com.demo.dao.ProdDao; +import com.demo.dao.ProdDaoImpl; + +//service layer class that implements ProdService interface +public class ProdServiceImpl implements ProdService { + static { + sc = new Scanner(System.in); + } + static Scanner sc; + private ProdDao pDao; + SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/YYY"); + + public ProdServiceImpl() { + + this.pDao = new ProdDaoImpl(); + } + + // method to add products based on choice + @Override + public void addProduct(String type) { + //accepting the details of the product + Products prod = null; + System.out.println("enter itm code"); + int itmNum = sc.nextInt(); + System.out.println("enter the itm name"); + String name = sc.next(); + System.out.println("enter the price"); + double price = sc.nextDouble(); + System.out.println("enter quantity"); + int qty = sc.nextInt(); + switch (type) { + case "food": + Date dtm=null,dte=null; + try { + System.out.println("enter the manufacture date"); + String dateM = sc.next(); + dtm = sdf.parse(dateM); + System.out.println("enter the expiry date"); + String dateE = sc.next(); + dte = sdf.parse(dateE); + } catch (ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + System.out.println("veg or not"); + boolean veg = sc.nextBoolean(); + prod = new Food(itmNum, name, price, qty, type, dtm, dte, veg); + pDao.addProduct(prod,type); + break; + case "apparel": + System.out.println("enter itm size"); + int size = sc.nextInt(); + System.out.println("enter the itm material"); + String material = sc.next(); + prod = new Apparel(itmNum, name, price, qty, type, size, material); + pDao.addProduct(prod,type); + break; + case "electronics": + System.out.println("enter warranty in months"); + int warranty = sc.nextInt(); + prod = new Electronics(itmNum, name, price, qty, type, warranty); + pDao.addProduct(prod,type); + break; + } + + } + + public Set getProds(String type){ + return pDao.getProds(type); + } + + +} diff --git a/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/src/com/demo/test/ProdTest.java b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/src/com/demo/test/ProdTest.java new file mode 100644 index 00000000..c37219c5 --- /dev/null +++ b/Practical_exam_bharadwaj_divatekodandarama_wfs4/ProductsExam/src/com/demo/test/ProdTest.java @@ -0,0 +1,22 @@ +package com.demo.test; + +import java.util.Scanner; + +import com.demo.bean.Products; +import com.demo.service.ProdService; +import com.demo.service.ProdServiceImpl; + +public class ProdTest { + + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner sc = new Scanner(System.in); + ProdService prodService = new ProdServiceImpl(); + String type = sc.next(); + prodService.addProduct(type); + + String ptype = sc.next(); + prodService.getProd(ptype); + + } +}