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

Shirshendhu panday #18

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
79 changes: 79 additions & 0 deletions Shirshendhu/Assesment 1/Account.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import java.util.Date;

public class Account{
private int perId;
private String perName;
private Date oDate;
private String typeOfAc;
private Double bal;
//private final String code="2308AB0";
public static int count=0;

//Default Constructor
public Account(){
count++;
perId=count;
perName=null;
bal=0.0;
oDate=null;
typeOfAc=null;
}

//Parameterized Constructor
public Account(String perName,Double bal,String typeOfAc,Date oDate){
count++;
perId=count;
this.perName=perName;
this.oDate=oDate;
this.typeOfAc=typeOfAc;
this.bal=bal;
}

//Overriding to display customized entries
@Override
public String toString(){

return "Id : "+perId+"\nName : "+perName+"\nBalance : "+bal+"\nDate of opening"+oDate+"\nAccount Type: "+typeOfAc+"\n";
}

//Setter getter methods

/*public void setPerId(int id){
this.perId=id;
}*/
public int getPerId(){

return this.perId;
}
public void setPerName(String pname){

this.perName=pname;
}
public String getPerName(){

return this.perName;
}
public void setTypeOfAc(String acType){
this.typeOfAc=acType;
}
public String getTypeOfAc(){
return this.typeOfAc;
}
public void setBalance(Double balance){

this.bal=balance;
}
public Double getBalance(){

return this.bal;
}


public void withdraw(Double bl){
if(bal-10000>=bl)
setBalance(bal-bl);
}
public void deposit(Double bl){
setBalance(bl+bal);
}
}
62 changes: 62 additions & 0 deletions Shirshendhu/Assesment 1/AccountService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import java.util.Date;
import java.util.Scanner;
//import java.text.SimpleDateFormat;
import java.text.ParseException;

public class AccountService{
public static Scanner sc=new Scanner(System.in);
//Create new account
public static void acceptAcData(Account[] parr){

for(int i=0;i<parr.length;i++){
System.out.println("Enter name");
String nm=sc.next();
System.out.println("Enter Account Type(Savings/Current)");
String acType=sc.next();
System.out.println("Enter Balance");
Double bal=sc.nextDouble();
//try{
parr[i]=new Account(nm,bal,acType,new Date());
System.out.println("Id is: ");
System.out.println(parr[i].getPerId());
/*}catch(ParseException e){
e.printStackTrace();
}*/
}
}
//Search by Id
public static int searchById(Account[] parr,int id){
for(int i=0;i<parr.length;i++){
if(parr[i].getPerId()==id)
return i;
}
return -1;
}
//Withdraw method
public static void withdrawAmt(Account[] arr,int id,double amt){
int pos=searchById(arr,id);
if(pos!=-1){
arr[pos].withdraw(amt);
displayAc(arr, id);
}
else
System.out.println("Person Not found");
}
//Deposit method
public static void depositAmt(Account[] arr,int id,double amt){
int pos=searchById(arr,id);
if(pos!=-1){
arr[pos].deposit(amt);
displayAc(arr, id);
}
else
System.out.println("Person Not found");
}

//Display the account
public static void displayAc(Account[] parr, int id){
int pos=searchById(parr,id);
System.out.println(parr[pos]);

}
}
49 changes: 49 additions & 0 deletions Shirshendhu/Assesment 1/TestAccountClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import java.util.Date;
import java.util.Scanner;

import java.text.ParseException;

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

public static void main(String args[]){
Account[] parr=new Account[3];
AccountService.acceptAcData(parr);
do{
System.out.println("Press 0 for Create accounts, 1 for Withdraw, 2 for Deposit, 3 for Display or 4 for Exit");
int c=sc.nextInt();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

//All options

switch(c) {
case 0:
AccountService.acceptAcData(parr);
break;
case 1:
System.out.println("Enter id to withdraw:");
int id = sc.nextInt();
System.out.println("Enter amount to withdraw:");
double bal = sc.nextDouble();
AccountService.withdrawAmt(parr, id,bal);

break;
case 2:
System.out.println("Enter id to deposit:");
id = sc.nextInt();
System.out.println("Enter amount to deposit:");
bal = sc.nextDouble();
AccountService.depositAmt(parr, id,bal);
break;
case 3:
System.out.println("Enter id to display:");
id = sc.nextInt();
AccountService.displayAc(parr, id);
break;
case 4:
System.exit(0);
break;
default:
System.out.println("Enter correct choice");
break;
}
}while(1==1);
}

}