Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accountinfo 1st assignment #4

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Binary file added AccountIE/bin/com/demo/bean/Account.class
Binary file not shown.
Binary file added AccountIE/bin/com/demo/bean/Current.class
Binary file not shown.
Binary file added AccountIE/bin/com/demo/bean/Savings.class
Binary file not shown.
Binary file added AccountIE/bin/com/demo/dao/AccountDao.class
Binary file not shown.
Binary file added AccountIE/bin/com/demo/dao/AccountDaoImp.class
Binary file not shown.
Binary file not shown.
Binary file added AccountIE/bin/com/demo/service/AccService.class
Binary file not shown.
Binary file not shown.
Binary file added AccountIE/bin/com/demo/test/AccountTest.class
Binary file not shown.
86 changes: 86 additions & 0 deletions AccountIE/src/com/demo/bean/Account.java
Original file line number Diff line number Diff line change
@@ -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;
}


}
37 changes: 37 additions & 0 deletions AccountIE/src/com/demo/bean/Current.java
Original file line number Diff line number Diff line change
@@ -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";
}
}
42 changes: 42 additions & 0 deletions AccountIE/src/com/demo/bean/Savings.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
23 changes: 23 additions & 0 deletions AccountIE/src/com/demo/dao/AccountDao.java
Original file line number Diff line number Diff line change
@@ -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);


}
77 changes: 77 additions & 0 deletions AccountIE/src/com/demo/dao/AccountDaoImp.java
Original file line number Diff line number Diff line change
@@ -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();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.demo.exception;

public class AccountNotFoundException extends Exception{
public AccountNotFoundException(String msg) {
super(msg);
}
}
26 changes: 26 additions & 0 deletions AccountIE/src/com/demo/service/AccService.java
Original file line number Diff line number Diff line change
@@ -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;

}
Loading