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

Added Files of First Code #2

Open
wants to merge 1 commit 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 OnkarJoshi/AccountDraft1/.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 OnkarJoshi/AccountDraft1/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>AutogenerateId</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 OnkarJoshi/AccountDraft1/.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.
87 changes: 87 additions & 0 deletions OnkarJoshi/AccountDraft1/src/com/demo/bean/Account.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.demo.bean;
import java.util.Date;


public class Account {
static {
cnt=0;
}
public static int cnt;
private int aID;
private String aName;
private String accType;
private double balance;
private Date oDate;

//default constructor
public Account() {
aID=++cnt; //Generates ID
aName=null;
accType=null;
balance=0;
oDate=null;
}
//parameterized constructor

public Account(String aName,String accType, double bal, Date oDate ) {
this.aID=++cnt;
this.aName=aName;
this.accType=accType;
this.balance=bal;
this.oDate=oDate;
}
//Setter and Getter methods

public int getPerId() {
return this.aID;
}
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 setDate(Date dt) {
this.oDate=dt;
}
public Date getDate() {
return this.oDate;
}
public void setAccType(String type) {
this.accType=type;
}
public String getAccType() {
return this.accType;
}
// end of getter and setter methods

//withdraw function with limit 10000
public void withdraw(double amt) {
if(balance-10000>=amt) {
balance=balance-amt;
}else {
System.out.println("Not enough balance!!..");
}
}
//deposit function

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

@Override //used to print using System.out.println
public String toString() {
return "Id : "+aID+" \nName : "+aName+" \nBalance: "+balance+" Type : "+accType+"\nDate of Opening: "+oDate;
}



}

79 changes: 79 additions & 0 deletions OnkarJoshi/AccountDraft1/src/com/demo/service/AccountService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.demo.service;
import com.demo.bean.Account;

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

public class AccountService {

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

public static void acceptAccountData(Account[] arr) { // accept people data
for(int i=0;i<arr.length;i++ ) {
System.out.println("Enter name:");
String nm=sc.next();
System.out.println("Enter balance:");
double bal=sc.nextDouble();
System.out.println("Enter account type:");
String ty=sc.next();
System.out.println("Enter Date of opening:");
String dt=sc.next();

try {
Date odate=sdf.parse(dt);
arr[i]= new Account(nm,ty,bal,odate);
}
catch(ParseException e) {
e.printStackTrace();
}

}
}

public static void displayAccount(Account[] arr) { //displays the details stored

for (int i=0;i<arr.length;i++) {
if(arr[i]!=null) {
System.out.println(arr[i]);
}else {
break;
}
}
}

public static void withdrawAmt(Account[]arr,double amt,int id) { // withdraw the money from account

int pos=AccountService.searchById(arr, id);
System.out.println(pos);
arr[pos].withdraw(amt);
System.out.println("Withdrawing....");
System.out.println("New balance is:");
System.out.println(arr[pos].getBalance());

}

public static void depositAmt(Account[]arr,double amt,int id) { //deposit the money to the account

int pos=AccountService.searchById(arr, id);
System.out.println(pos);
arr[pos].deposit(amt);
System.out.println("New balance is:");
System.out.println(arr[pos].getBalance());
}

public static int searchById(Account[] arr, int id) { //Search for a person by id

for(int i=0;i<arr.length;i++) {
if(arr[i].getPerId()== id) {
return i;
}
}
return -1;
}


}

58 changes: 58 additions & 0 deletions OnkarJoshi/AccountDraft1/src/com/demo/test/TestAccountClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.demo.test;
import com.demo.bean.Account;
import com.demo.service.*;
import java.util.Date;
import java.util.Scanner;

public class TestAccountClass {

public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
Account[] a=new Account[1];
System.out.println("Please enter all 10 account details:");
AccountService.acceptAccountData(a);

// the menu shown to users

while(true) {
System.out.println("------Welcome to xxxx BANK------");
System.out.println("1.Withdraw \n2.Deposit \n3.Display your Account details \n4.Exit");
int i=sc.nextInt();



//switch case for the menu
switch(i) {
case 1:
System.out.println("Please enter your Account Id:");
int id1=sc.nextInt();
System.out.println("Enter amount to be withdrawn:");
double amt=sc.nextInt();
AccountService.withdrawAmt(a,amt,id1);
break;
case 2:
System.out.println("Please enter your Account Id:");
int id2=sc.nextInt();
System.out.println("Enter amount to be deposited:");
double amt1=sc.nextInt();
AccountService.depositAmt(a,amt1,id2);
break;
case 3:
System.out.println("Please enter your Account Id:");
int id3=sc.nextInt();
int s;
s=AccountService.searchById(a, id3);
if(s!=1) {
System.out.println(a[s]);
}

break;
case 4:
System.exit(0);
}


}

}
}