Skip to content

Commit

Permalink
Bank Account Details
Browse files Browse the repository at this point in the history
  • Loading branch information
cybernobie authored May 18, 2021
1 parent b120494 commit c683c47
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
public class Account{
private int accountId;
private String accountType;
private int balance;

public int getAccountId() {
return accountId;
}
public void setAccountId(int accountId) {
this.accountId = accountId;
}
public String getAccountType() {
return accountType;
}
public void setAccountType(String accountType) {
this.accountType = accountType;
}
public int getBalance() {
return balance;
}
public void setBalance(int balance) {
this.balance = balance;
}

public boolean withdraw(int amount){
if(balance >= amount){
balance -= amount;
System.out.println("Balance amount after withdraw:"+balance);
return true;
}else{
System.out.println("Sorry!!! No enough balance");
return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import java.util.*;
public class AccountDetails{
Scanner sc = new Scanner(System.in);

public Account getAccountDetails(){
Account a = new Account();
System.out.println("Enter account id:");
int id = sc.nextInt();

System.out.println("Enter account type:");
String type = sc.next();
while(true){
System.out.println("Enter balance:");
int bal = sc.nextInt();
if(bal<=0){
System.out.println("Balance should be positive");
}
else{
a.setBalance(bal);
break;
}
}
a.setAccountId(id);
a.setAccountType(type);

return a;

}

public int getWithdrawAmount(){

int amt;
while(true){
System.out.println("Enter amount to be withdrawn:");
amt = sc.nextInt();
if(amt<=0){
System.out.println("Amount should be positive");
continue;
}
else
break;
}
return amt;

}

public static void main(String[] args){

AccountDetails ad = new AccountDetails();
Account a = ad.getAccountDetails();
boolean with_drawn = a.withdraw(ad.getWithdrawAmount());

}
}

0 comments on commit c683c47

Please sign in to comment.