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

Adrija ghansiyal #9

Open
wants to merge 7 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 AccountAssignment/.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"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions AccountAssignment/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>AccountAssignment</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>
Binary file added AccountAssignment/bin/com/demo/bean/Account.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
86 changes: 86 additions & 0 deletions AccountAssignment/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;

public class Account {

private int accId;
private String accName;
private Date dateOfOpening;
private String typeOfAcc;
private double balance;

final String ifsc="HSBC001";

//default constructor
public Account() {
accId= 0;
accName=null;
dateOfOpening=null;
typeOfAcc=null;
balance=0;
}
//parameterized constructor
public Account(int id,String name,String typeAcc,double bal) {
accId=id;
accName=name;
dateOfOpening=new Date();
typeOfAcc=typeAcc;
balance=bal;
}

//setters and getters
public void setAccId(int id) {
this.accId=id;
}
public int getAccId() {
return this.accId;
}
public void setName(String name) {
this.accName=name;
}
public String getName() {
return this.accName;
}
public void setDate(Date dOpen) {
this.dateOfOpening=dOpen;
}
public Date getDate() {
return this.dateOfOpening;
}
public void setBalance(double bal) {
this.balance=bal;
}
public double getBalance() {
return this.balance;
}
public void setType(String typeAcc) {
this.typeOfAcc=typeAcc;
}
public String getType() {
return this.typeOfAcc;
}

//to withdraw amount from an account
public void withdrawal(double amt) {
if((balance-10000)>=amt) {
balance=balance-amt;
System.out.println("Successfully withdrawn");
}
else
System.out.println("not enough balance");
}

//to deposit in an account
public void deposition(double amt) {
balance=balance+amt;
System.out.println("Successfully deposited");
}

//to display data of the user
public String toString() {
return "AccId: "+accId+"\nName: "+accName+"\ndate Of Opening: "+dateOfOpening+"\nAccount Type: "
+typeOfAcc+"\nBalance: "+balance;

}

}
85 changes: 85 additions & 0 deletions AccountAssignment/src/com/demo/service/AccountService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.demo.service;
import java.util.Date;
import java.util.Scanner;

import com.demo.bean.Account;

//import java.text.ParseException;
import java.text.SimpleDateFormat;

public class AccountService {

public static Scanner sc=new Scanner(System.in);

//to search person account by id
public static int searchById(Account[] acarr,int id) {
for(int i=0;i<acarr.length;i++) {
if(id==acarr[i].getAccId()) {
return i;
}
}
return -1;

}

//to create an account --->currently creating 3 accounts together
public static void acceptAccountData(Account acarr[]) {
for(int i=0;i<acarr.length;i++) {
System.out.println("Enter id");
int id=sc.nextInt();
System.out.println("Enter name");
String name=sc.next();
System.out.println("Enter Type of account");
String typeAcc=sc.next();
System.out.println("Enter balance");
double bal=sc.nextDouble();
acarr[i]=new Account(id,name,typeAcc,bal);
}
//displayAllAccounts(acarr);

}

//to withdraw from an account based on account id
public static void withdraw(Account acarr[],int id,Double withdrawAmt) {

int pos=searchById(acarr,id);
if(pos!=-1) {
acarr[pos].withdrawal(withdrawAmt); //calling Account method
}
else
System.out.println("user not found");

}

//to deposit to an account based on account id
public static void deposit(Account acarr[],int id,Double depositAmt) {
int pos=searchById(acarr,id);
if(pos!=-1) {
acarr[pos].deposition(depositAmt);
}
else
System.out.println("No user exist");

}

//to display data for an account by id
public static void displayAccount(Account acarr[],int id) {
int pos=searchById(acarr,id);
if(pos!=-1)
System.out.println(acarr[pos]);
else
System.out.println("no user found");

}

//to display data for all accounts
public static void displayAllAccounts(Account[] acarr) {
for(int i=0;i<acarr.length;i++) {
if(acarr[i]!=null)
System.out.println(acarr[i]);
else
break;
}

}
}
53 changes: 53 additions & 0 deletions AccountAssignment/src/com/demo/test/TestAccountClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.demo.test;
import java.util.Scanner;

import com.demo.bean.Account;
import com.demo.service.AccountService;

public class TestAccountClass {

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);
Account[] a=new Account[3];

//menu for the customer
int choice;
do{
System.out.println("\nEnter the number: (1) create a/c (2) withdraw (3) deposit "
+ "(4) display a/c by id (5) exit");
choice=sc.nextInt();
switch(choice) {
case 1:
AccountService.acceptAccountData(a);
break;
case 2:
System.out.println("Enter account id");
int id=sc.nextInt();
System.out.println("Enter withdraw amount");
Double amt=sc.nextDouble();
AccountService.withdraw(a,id,amt);
break;
case 3:
System.out.println("Enter account id");
id=sc.nextInt();
System.out.println("Enter deposit amount");
amt=sc.nextDouble();
AccountService.deposit(a,id,amt);
break;
case 4:
System.out.println("Enter account id");
id=sc.nextInt();
AccountService.displayAccount(a,id);
break;
case 5:
System.out.println("exited");
System.exit(0);
break;
default: System.out.println("wrong option");
}
}while(choice!=5);
//System.out.print(Account.count); //finally showing total number of accounts
}

}
Binary file added AccountException/bin/com/demo/bean/Account.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added AccountException/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.
86 changes: 86 additions & 0 deletions AccountException/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;

import com.demo.exception.InsufficientBalanceException;

public abstract class Account {
static {
count=0;
}

public static Integer count;

private String accId;
private String accName;
private double balance;
private int pin;
private String typeAcc;

final String ifsc="HSBC00";

//default constructor
public Account() {
accId= "";
accName=null;
balance=0.0;
typeAcc=null;
pin=0;
}
//parameterized constructor
public Account(String name,double bal,String type,int pin) {
++count;
accId=ifsc+ count.toString();
accName=name;
balance=bal;
this.typeAcc=type;
this.pin=pin;
}

//setters and getters

public String getAccId() {
return this.accId;
}
public void setName(String name) {
this.accName=name;
}
public String getName() {
return this.accName;
}
public void setBalance(double bal) {
this.balance=bal;
}
public double getBalance() {
return this.balance;
}
public int getPin() {
return this.pin;
}
public void setPin(int pin) {
this.pin=pin;
}
public String getTypeAcc() {
return typeAcc;
}
public void setTypeAcc(String typeAcc) {
this.typeAcc = typeAcc;
}

//to withdraw amount from an account
public abstract int withdrawal(double amt) throws InsufficientBalanceException;

//to deposit in an account
public void deposition(double amt) {
balance=balance+amt;
System.out.println("Successfully deposited");
}

//to display data of the user
@Override
public String toString() {
return "AccId: "+accId+"\nName: "+accName+"\nBalance: "+balance+"\nType: "+typeAcc+"\npin: "+pin;

}

}
54 changes: 54 additions & 0 deletions AccountException/src/com/demo/bean/CurrentAcc.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.demo.bean;

import com.demo.exception.InsufficientBalanceException;

public class CurrentAcc extends Account {

private final int maxNoOfTrans=3;
private static final float interestRate=0.2f;
private int noOfTrans;
//default constructor
public CurrentAcc() {
noOfTrans=0;
//System.out.println("default constructor current a/c");
}
//parameterized constructor
public CurrentAcc(String name,double bal,String type,int pin) {
super(name,bal,type,pin);
//System.out.println("Param constructor current a/c");
noOfTrans=0;
}
//setters and getters
public int getTrans() {
return this.noOfTrans;
}
public void setTrans(int trans) {
this.noOfTrans=trans;
}


//overriding withdrawal method
public int withdrawal(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");
//return -1;
}
//to get total interest
public double getInterest() {
return getBalance()*interestRate;
}
//toString method overridden
public String toString() {
return super.toString()+"\ninterest rate: "+this.interestRate+"\nno of transactions.: "
+this.noOfTrans+"\ntotal interest amt: "+this.getInterest();
}



}
Loading