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

Assignment 3 #27

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions AccountFinalDraft2/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions AccountFinalDraft2/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>AccountFinalDraft2</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
12 changes: 12 additions & 0 deletions AccountFinalDraft2/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added AccountFinalDraft2/bin/com/demo/dao/AccountDao.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
98 changes: 98 additions & 0 deletions AccountFinalDraft2/src/com/demo/bean/Account.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package com.demo.bean;
import java.util.Date;

import com.demo.exception.InsufficientBalanceException;


abstract public class Account {
static {
cnt=0;
iR=0;
}
public static int cnt;
private int aID;
protected String code;
protected String acNo;
private String aName;
private int pin;
private String accType;
private double balance;
public static int iR;


public Account() {
aID=++cnt;
acNo="BANKxxx"+cnt;;
aName=null;
pin=0;
accType=null;
balance=0;

}

public Account(String aName,int pin, double bal,String accType) {
this.aID=++cnt;
acNo="BANKxxx"+cnt;
this.aName=aName;
this.pin=pin;
this.accType=accType;
this.balance=bal;
}
//Setter and Getter methods

public String getAcNo() {
return acNo;
}

public int getPin() {
return pin;
}

public void setPin(int pin) {
this.pin = pin;
}

public int getPerId() {
return this.aID;
}
public String getPerAcc() {
return this.acNo;
}
public void setPerName(String name) {
this.aName=name;
}
public String getPerName() {
return this.aName;
}

public void setBalance(double bal) {
this.balance=bal;
}
public double getBalance() {
return this.balance;
}


public void setAccType(String type) {
this.accType=type;
}
public String getAccType() {
return this.accType;
}
// end of getter and setter methods

abstract public int withdraw(double amt) throws InsufficientBalanceException;

public void deposit(double amt) {
balance=balance+amt;
}

@Override
public String toString() {
return "Id : "+aID+"\nAccount No.:"+acNo+" \nName : "+aName+" \nBalance: "+balance+" Type : "+accType;
}



}

59 changes: 59 additions & 0 deletions AccountFinalDraft2/src/com/demo/bean/CurrentAcc.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.demo.bean;
import com.demo.exception.*;
import java.util.Date;
import java.util.Scanner;
import com.demo.service.AccountService;

public class CurrentAcc extends Account {


public static Scanner sc=new Scanner(System.in);
static {
iR=0.2;
}

public static double iR;
private int noOfTrans;
private final int maxTrans=3;

//default Constructor
public CurrentAcc() {
noOfTrans=0;
}

public CurrentAcc(String aName,int pin, double bal, String accType) {
super(aName,pin,bal,accType);
noOfTrans=0;
}
//setter getter to get number of transactions over
public int getNoOfTrans() {
return noOfTrans;
}

public void setNoOfTrans(int noOfTrans) {
this.noOfTrans = noOfTrans;
}

public int withdraw(double amt) throws InsufficientBalanceException{
if((getBalance())>=amt) {
setBalance(getBalance()-amt);
System.out.println("Successfully withdrawn from current a/c");
++noOfTrans;
return 1;
}
else
throw new InsufficientBalanceException("Insufficient Balance");

}

public double interestCal() {
return getBalance()*iR;
}

public String toString() {
return super.toString()+"\nInterest Rate: "+iR+"\nNo of Transactions.: "+this.noOfTrans+"\nTotal interest Calculated: "+interestCal();
}

}


51 changes: 51 additions & 0 deletions AccountFinalDraft2/src/com/demo/bean/SavingsAcc.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.demo.bean;
import java.util.Scanner;
import com.demo.exception.*;

public class SavingsAcc extends Account {

public static Scanner sc=new Scanner(System.in);
static {
iR=4;
}
public static double iR;
private String cheqbNo;

public SavingsAcc() {
super();
}

public SavingsAcc(String aName,int pin, double bal ,String accType) {
super(aName,pin,bal,accType);
this.cheqbNo = acNo;
}

//withdraw from account
public int withdraw(double amt) throws InsufficientBalanceException {
if((getBalance()-10000)>=amt) {
setBalance(getBalance()-amt);
System.out.println("Withdrawn Successful(savings a/c).....");
return 1;
}
else
throw new InsufficientBalanceException("Insufficient Balance.....");


}

//calculate interest
public double interestCal() {
if(getBalance()>50000) {
return (getBalance()*iR)+(getBalance()*0.02);
}
else {
return getBalance()*iR;
}
}

public String toString() {
return super.toString()+"\nInterest Rate: "+iR+"\nCheque No.: "
+cheqbNo+"\nTotal Interest Calculated: "+interestCal();
}
}

21 changes: 21 additions & 0 deletions AccountFinalDraft2/src/com/demo/dao/AccountDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.demo.dao;

import com.demo.exception.*;

import java.util.Set;

import com.demo.bean.Account;

public interface AccountDao {

void newAccount(Account a);

Account searchId(String id);

void deposit(Account arr, double amt);

Set<Account> displayAll();

void withdraw(Account a, Double amt) throws InsufficientBalanceException;

}
52 changes: 52 additions & 0 deletions AccountFinalDraft2/src/com/demo/dao/AccountDaoImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.demo.dao;
import com.demo.exception.*;

import java.util.HashSet;
import java.util.Set;

import com.demo.bean.Account;
import com.demo.exception.*;

public class AccountDaoImpl implements AccountDao {
static Set<Account> aset;
static {
aset=new HashSet<>();
}

//Create new account
@Override
public void newAccount(Account a) {
aset.add(a);
}


//searches for the id
@Override
public Account searchId(String id) {
for(Account a:aset) {
if(a.getAcNo().equals(id) ){
return a;
}
}
return null;
}
// calls withdraw from either savings or current account
@Override
public void withdraw(Account a,Double amt) throws InsufficientBalanceException {
a.withdraw(amt);
}

// calls deposit from account
@Override
public void deposit(Account a,double amt) {
a.deposit(amt);
}

//Displays all the Account Details
@Override
public Set<Account> displayAll() {
return aset;
}


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

public class IncorrectPinException extends Exception{
public IncorrectPinException(String msg) {
super(msg);
}

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

public class InsufficientBalanceException extends Exception {
public InsufficientBalanceException(String msg) {
super(msg);
}

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

public class InvalidAccTypeException extends Exception {
public InvalidAccTypeException(String msg) {
super(msg);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.demo.exception;

public class LimitExceedException extends Exception {
public LimitExceedException(String msg) {
super(msg);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.demo.exception;

public class PinMismatchException extends Exception {
public PinMismatchException(String msg) {
super(msg);
}
}


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

public class UserNotFoundException extends Exception {
public UserNotFoundException(String msg) {
super(msg);
}
}
19 changes: 19 additions & 0 deletions AccountFinalDraft2/src/com/demo/service/AccountService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.demo.service;

import com.demo.bean.Account;
import com.demo.exception.*;
public interface AccountService {

void acceptAccountData() throws LimitExceedException;

void withdraw(String id, Double amt) throws InsufficientBalanceException, UserNotFoundException;

void deposit(String id, Double amt) throws UserNotFoundException;

void displayAccount(String id) throws UserNotFoundException;

void transfer(String idSource, double amt) throws InsufficientBalanceException, UserNotFoundException;

void changePin(String id) throws UserNotFoundException, LimitExceedException;

}
Loading