forked from cybernobie/Cognizant_Early_Engagement
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b120494
commit c683c47
Showing
2 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
...ng Funcamentals and Soft Skills/Java Programming Language/BankAccountDetails/Account.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...amentals and Soft Skills/Java Programming Language/BankAccountDetails/AccountDetails.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
|
||
} | ||
} |