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

Submitting Assignment 2 #20

Open
wants to merge 2 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
Binary file added Assignent1/bin/com/assign/bean/Account.class
Binary file not shown.
Binary file added Assignent1/bin/com/assign/bean/CurrentAcc.class
Binary file not shown.
Binary file added Assignent1/bin/com/assign/bean/SavingsAcc.class
Binary file not shown.
Binary file not shown.
Binary file added Assignent1/bin/com/assign/test/TestAccount.class
Binary file not shown.
86 changes: 86 additions & 0 deletions Assignent1/src/com/assign/bean/Account.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.assign.bean;

import java.util.Date;

abstract public class Account {
static {
cnt = 0;
rate = 4.0f;
}
public static int cnt;
static float rate;
private int accId;
private String name;
private Date openingDate;
private String accType;
protected double balance;
private int pin;
protected double interest;

//default constructor
public Account() {
accId = ++cnt;
name = null;
openingDate = null;
accType = null;
balance = 0.0;
rate = 0.0f;
pin = 0;
}
//parameterized constructor
public Account(String nm, Date dt, String type, double bal, int pin) {
accId = ++cnt;
name = nm;
openingDate = dt;
accType = type;
balance = bal;
this.pin = pin;
}
//setter and getter methods
public int getAccId() {
return this.accId;
}
public void setName(String nm) {
this.name = nm;
}
public String getName() {
return this.name;
}
public void setOpeningDate(Date dt) {
this.openingDate = dt;
}
public Date getOpeningDate() {
return this.openingDate;
}
public void setAccType(String type) {
this.accType = type;
}
public String getAccType() {
return this.accType;
}
public void setBalance(double bal) {
this.balance = bal;
}
public double getBalance() {
return this.balance;
}
public void setPin(int pin) {
this.pin = pin;
}
public int getPin() {
return this.pin;
}
@Override
public String toString() {
return "Id : "+accId+"\nName : "+name+"\nOpening Date : "+openingDate+"\nAccount Type : "+accType+"\nBalance : "+balance+"\nRate of Interest : "+rate;
}
//withdrawal function
abstract public int withdrawal(double amt);
//deposit function
public void deposit(double amt) {
balance+=amt;
//System.out.println("Deposit Successful!");
//System.out.println("Balance : "+balance);
}
abstract public void calInterest();
}
41 changes: 41 additions & 0 deletions Assignent1/src/com/assign/bean/CurrentAcc.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.assign.bean;

import java.util.Date;

public class CurrentAcc extends Account{
static {
noOfTransPerDay = 3;
}
static int noOfTransPerDay;

//default constructor
public CurrentAcc() {

}
//parameterized constructor
public CurrentAcc(String nm, Date dt, String type, double bal, int pin) {
super(nm,dt,type,bal,pin);
calInterest();
}
//setter and getter methods
@Override
public String toString() {
return super.toString()+"\nNo. of transactions per day : "+noOfTransPerDay+"\nInterest : "+interest;
}
@Override
public int withdrawal(double amt) {

if(amt <= balance) {
balance-=amt;
return 0;
//System.out.println("Withdrawal Successful!");
//System.out.println("Balance : "+balance);
}
return -1;
}
@Override
public void calInterest() {

interest = balance*rate;
}
}
51 changes: 51 additions & 0 deletions Assignent1/src/com/assign/bean/SavingsAcc.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.assign.bean;

import java.util.Date;

public class SavingsAcc extends Account {
private long chequeBookNo;

//default constructor
public SavingsAcc() {
chequeBookNo = 0;
}
//parameterized constructor
public SavingsAcc(String nm, Date dt, String type, double bal, int pin, long chequeBkNo) {
super(nm,dt,type,bal,pin);
this.chequeBookNo = chequeBkNo;
calInterest();
}
//setter and getter methods
public void setChequeBookNo(long chequeBkNo) {
this.chequeBookNo = chequeBkNo;
}
public long getChequeBookNo() {
return this.chequeBookNo;
}
@Override
public String toString() {
return super.toString()+"\nCheque Book No. : "+chequeBookNo+"\nInterest : "+interest;
}
@Override
public int withdrawal(double amt) {

if(amt <= balance-10000) {
balance-=amt;
return 0;
//System.out.println("Withdrawal Successful!");
//System.out.println("Balance : "+balance);
}
return -1;
}
@Override
public void calInterest() {

if(balance > 5000)
{
interest = (balance*rate) + (0.02*balance);
}
else
interest = balance*rate;
}

}
124 changes: 124 additions & 0 deletions Assignent1/src/com/assign/service/AccountService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package com.assign.service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

import com.assign.bean.*;

public class AccountService {

public static SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
public static Scanner sc = new Scanner(System.in);

//create a new account
public static void createAccount(Account[] arr, String type, int i) {
//for(int i=0;i<arr.length;i++)
if(i<arr.length) {
System.out.println("Enter Name");
String nm = sc.next();
System.out.println("Enter PIN");
int pin = sc.nextInt();
System.out.println("Enter Balance");
double bal = sc.nextDouble();
if(type.equals("Savings")) {
System.out.println("Enter Cheque Book No.");
long chequeBkNo = sc.nextLong();
arr[i] = new SavingsAcc(nm, new Date(), type, bal,pin,chequeBkNo);
}
else
arr[i] = new CurrentAcc(nm, new Date(), type, bal,pin);
System.out.println("Account created successfully!");
}
else {
System.out.println("Account cannot be created, Sorry!");
}
}
//search an account
public static int searchAccount(Account[] arr, int id) {

for(int i=0;i<arr.length;i++) {
if(arr[i].getAccId()==id) {
return i;
}
}
return -1;
}
//withdrawal function
public static void withdrawAmt(Account[] arr, int id, double amt) {
//check if the account exists
int check = searchAccount(arr,id);
if(check==-1) {
System.out.println("Account not found");
}
else {
//call withdrawal function of respective class
int res = arr[check].withdrawal(amt);
if(res==0)
System.out.println("Withdrawal Successful!");
else
System.out.println("Insufficient balance");
}
}
//deposit function
public static void depositAmt(Account[] arr, int id, double amt) {
//check if the account exists
int check = searchAccount(arr,id);
if(check == -1) {
System.out.println("Account not found");
}
else {
//call deposit function of Account class
arr[check].deposit(amt);
}
}
//transfer function
public static void transfer(Account[] arr, int id1,int id2, double amt) {

//check if both accounts exist
int a1,a2,res;
a1=searchAccount(arr, id1);
if(a1 == -1) {
System.out.println("Account to transfer from not found");
return;
}
a2=searchAccount(arr,id2);
if(a2==-1) {
System.out.println("Account to be transferred to not found");
return;
}
res=arr[a1].withdrawal(amt);
if(res==-1) {
System.out.println("Insufficient balance to transfer");
return;
}
else {
arr[a2].deposit(amt);
}
System.out.println("Transfer Successful!");
}
public static int checkPin(Account[] arr,int res, int pin) {

if(arr[res].getPin()==pin) {
return 0;
}
else
return -1;
}
public static void changePin(Account[] arr, int pin,int res) {

arr[res].setPin(pin);
System.out.println("PIN updated successfully");
}
public static void checkBalance(Account[] arr, int id) {

int res = searchAccount(arr,id);
if(res == -1) {
System.out.println("Account not found");
return;
}
else {
System.out.println(arr[res].getBalance());
}
}
}
Loading