Skip to content

Instantly share code, notes, and snippets.

@samuelmale
Last active November 20, 2019 09:19
Show Gist options
  • Save samuelmale/48c1fe974cea0d80c812585e765561f5 to your computer and use it in GitHub Desktop.
Save samuelmale/48c1fe974cea0d80c812585e765561f5 to your computer and use it in GitHub Desktop.
/**
* This defines a generic {@link Bank} account {@link User}s can own
*
* @author samuel
*
*/
public class Account {
// account number
private Integer accountNumber;
// name of the account
private String name;
// account balance, default is 0
private Double balance = 0.0;
// the type of the account
private AccountType type;
// Default constructor
public Account() {
}
public Account(Integer accountNumber, String name, Double balance) {
super();
this.accountNumber = accountNumber;
this.name = name;
this.balance = balance;
}
public Integer getAccountNumber() {
return accountNumber;
}
public void setAccountNumber(Integer accountNumber) {
this.accountNumber = accountNumber;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Double getBalance() {
return balance;
}
public void setBalance(Double balance) {
this.balance = balance;
}
public AccountType getType() {
return type;
}
public void setType(AccountType type) {
this.type = type;
}
//////////////////////////////////////////
// Utility methods can live here
//////////////////////////////////////////
}
/**
* There lots of {@link Account} types a bank can support, this defines those we provide
*
* @author samuel
*/
public enum AccountType {
/**
* This is a savings account, see: https://en.wikipedia.org/wiki/Savings_account
*/
SAVINGS,
/**
* These are simple accounts in favor of the none working class
*/
STUDENT,
/**
* These are accounts held by the big dogs like: Kuteesa Sam ne Ann
*/
CORPORATE
}
import java.util.Scanner;
public class BankApp {
private String accno;
private String name;
private long balance;
Scanner sc = new Scanner(System.in);
//method to open an account
void openAccount()
{
System.out.print("Enter Account No.");
accno=sc.next();
System.out.print("Enter Name:");
name=sc.next();
System.out.print("Enter Balance:");
balance=sc.nextLong();
}
//method to display account details
void showAccount()
{
System.out.println(accno+","+name+","+balance);
}
//method to deposit
void deposit()
{
long amt;
System.out.println("Enter Amount You Would like to deposit");
amt = sc.nextLong();
}
//method to withdraw
void withdraw()
{
long amt;
System.out.println("Enter amount you would like to withdarw");
amt = sc.nextLong();
if(balance>=amt)
{
balance = balance-amt;
}
}
{
System.out.print("less Balance. Transation failed!!!");
}
//method to search for account
boolean search(String acn)
{
if(accno.equals(acn))
{
showAccount();
return(true);
}
return(false);
}
}
class ExBank
{
private static final String C = null;
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
// create initial accounts
System.out.print("How many customer you want to input:");
int n = sc.nextInt();
Bank C[]= new Bank[n];
for(int i =0; i<C.length;i++)
{
C[i]=new Bank();
C[i].openAccount();
}
}
//...........................................
int ch;
{
do{
System.out.println("Main Menu\n"
+ "1.Display All\n "
+ "2.Search By Account\n "
+ "3.Deposit\n"
+ "4.Withdrawal\n 5.Exit");
System.out.println("Ur Choice");
ch = sc.nextInt();
switch(ch)
{
case 1:
for(int i =0; i<C.length();i++)
{
C[i].showAccount();
}
break;
case 2:
System.out.print("Enter Account no you want to search...:");
String acn = sc.next();
boolean found=false;
for(int i=0;i<C.length;i++)
{
found=C[i].search(acn);
if (!found)
{
System.out.println("Search failed Account dosent exist....:");
}break;
}
case 3:
System.out.print("Enter Account No :");
acn=sc.next();
found= false;
for(int i=0; i<C.lenght; i++)
{
found = C[i].search(acn);
if(found)
{
C[i].deposit();
break;
}
}
if (!found)
{System.out.println("Search failed Account dosent exist....:");
}
break;
case 4:System.out.print("Enter Account No :");
acn=sc.next();
found =false;
for(int i=0; i<C.length; i++)
{found=C[i].search(acn);
if(found) {
C[i].withdrawal();
break;
}
if (!found)
{
System.out.print("Search failled,account not exsit");
}
break;
}
case 5:
System.out.println("Good Bye.......");
break;
}
}
while(ch!=5);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment