Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Bank {
- String name;
- static Account[] accounts = new Account[80];
- static int current = 0;
- static String manager = "Doctor Who";
- public static void main(String[] args) {
- Account acnt1 = new Account("Murad", 189863345L, 100.0, false);
- System.out.println("Is account of " + acnt1.getName() + " added? " + createAccount(acnt1));
- Account acnt2 = new Account("Amos", 1242426776L, 200.0, true);
- System.out.println("Is account of " + acnt2.getName() + " added? " + createAccount(acnt2));
- Account acnt3 = new Account("Murad", 189863345L, 1000000.0, true);
- System.out.println("Is account of " + acnt3.getName() + " added? " + createAccount(acnt3));
- System.out.println("*********************************");
- System.out.println("Welcome to Nucha-plata bank");
- System.out.println("Current manager:" + manager + "***");
- System.out.println("Is " + manager + " corrupted? " + corrupted());
- System.out.println("*********************************");
- Account pica = new Account("Picachu", 111111111L, 1000000.0, true);
- createAccount(pica);
- System.out.println("1000 euro to " + pica.getName() + " success? " + deposit(pica, "Doctor Who", 1000));
- }
- public static boolean createAccount(Account account) {
- if(current == 79) {
- System.out.println("The bank os full, can't add new user\nSorry");
- return false;
- }
- String owner = account.getName();
- for(int i=0; i<current; i++) {
- if(accounts[i].getName().equals(owner) && accounts[i].getId() == account.getId()) {
- System.out.println("A user with these details already exists\nNo account was created");
- return false;
- }
- }
- accounts[current] = account;
- current++;
- return true;
- }
- public static void change_management(String name) {
- manager = name;
- }
- public static boolean corrupted() {
- for (int i=0; i<current; i++) {
- if(accounts[i].getName().equals(manager) && accounts[i].isVip() == true)
- return true;
- }
- return false;
- }
- public static boolean withdrawal(Account account, String teller, double amount) {
- if(!teller.equals(manager))
- return false;
- for(int i=0; i<current; i++) {
- if(accounts[i].getName().equals(account.getName()) && accounts[i].getId() == account.getId()) {
- if(accounts[i].getBalance() < amount) {
- System.out.println("Only " + accounts[i].getBalance() + " was withdrawaled");
- accounts[i].setBalance(0);
- }
- else {
- accounts[i].setBalance(accounts[i].getBalance() - amount);
- System.out.println("Successfull withdrawal");
- }
- }
- }
- System.out.println("There is not such an account in our bank!");
- return false;
- }
- public static boolean deposit(Account account, String teller, double amount) {
- if(!teller.equals(manager))
- return false;
- for(int i=0; i<current; i++) {
- if(accounts[i].getName().equals(account.getName()) && accounts[i].getId() == account.getId()) {
- accounts[i].setBalance(accounts[i].getBalance() + amount);
- System.out.println("Successfull deposit");
- return true;
- }
- }
- System.out.println("There is not such an account in our bank!");
- return false;
- }
- }
Add Comment
Please, Sign In to add comment