Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JOptionPane;
- import static java.lang.System.exit;
- public class Bank {
- public static void main(String[] args) {
- String openAccount = JOptionPane.showInputDialog(null, "Do you want to open a Bank Account?:\n(1) YES\n(0) NO");
- int accountOpener = Integer.parseInt(openAccount);
- if (accountOpener == 1){
- String typeofAccount = JOptionPane.showInputDialog(null, "Account Type:\n1- Current Account\n2-Savings Account\n3-Student Account");
- int accountType = Integer.parseInt(typeofAccount);
- MethodCalls insert = new MethodCalls();
- insert.insertItem(accountType);
- String options = JOptionPane.showInputDialog(null," 1- Diposit\n 2 - Withdraw\n 3 - Display\n0- Exit");
- int option = Integer.parseInt(options);
- if(option==1) {
- insert.depositAmount(accountType);
- }
- else if(option ==2) {
- insert.withdrawAmount(accountType);
- }
- else if(option==3){
- insert.checkBalance(accountType);
- }
- else{
- exit(0);
- }
- }
- }
- }
- //import javax.swing.*;
- import java.util.ArrayList;
- import java.util.List;
- public class MethodCalls {
- List<BankAccount> account = new ArrayList<BankAccount>();
- BankAccount currentaccount = new CurrentAccount("",0,0.0,0.0);
- BankAccount savingsaccount = new SavingsAccount("",0.0,0.0);
- BankAccount studentaccount = new StudentAccount("","",0.0,0.0);
- void insertItem(int type){
- String accountHolder = JOptionPane.showInputDialog(null, "Name of the Account Holder:");
- String initialBalance = JOptionPane.showInputDialog(null, "Initial Amount:");
- double init = Double.parseDouble(initialBalance);
- if(type==1){
- currentaccount = new CurrentAccount(accountHolder,2856378, init, 5000);
- account.add(currentaccount);
- }
- else if(type==2) {
- savingsaccount = new SavingsAccount(accountHolder, init, 2000);
- account.add(savingsaccount);
- }
- else if(type==3){
- studentaccount = new StudentAccount(accountHolder,"UIU", init, 100);
- account.add(studentaccount);
- }
- }
- void depositAmount(int type){
- String deposit = JOptionPane.showInputDialog( "Deposit Amount:");
- double depositAmount = Double.parseDouble(deposit);
- if (type == 1) {
- currentaccount.deposit(depositAmount);
- currentaccount.getBalance();
- JOptionPane.showMessageDialog(null, "Updated Balance:\n" + currentaccount.getBalance());
- } else if (type == 2) {
- savingsaccount.deposit(depositAmount);
- savingsaccount.getBalance();
- JOptionPane.showMessageDialog(null, "Updated Balance:\n" + savingsaccount.getBalance());
- } else if (type == 3) {
- studentaccount.deposit(depositAmount);
- studentaccount.getBalance();
- JOptionPane.showMessageDialog(null, "Updated Balance:\n" + studentaccount.getBalance());
- }
- }
- void withdrawAmount(int type){
- String withdraw = JOptionPane.showInputDialog(null, "Amount to Withdraw:");
- double withdrawAmount = Double.parseDouble(withdraw);
- String check = JOptionPane.showInputDialog(null, "Do you wish to check your Account Balance?\n(1) Yes\n(0) No");
- int balanceCheck = Integer.parseInt(check);
- if (balanceCheck == 1) {
- if (type == 1) {
- currentaccount.getBalance();
- JOptionPane.showMessageDialog(null, "Balance:\n" + currentaccount.getBalance());
- currentaccount.withdrawl(withdrawAmount);
- currentaccount.getBalance();
- JOptionPane.showMessageDialog(null, "Updated Balance:\n" + currentaccount.getBalance());
- } else if (type == 2) {
- savingsaccount.getBalance();
- JOptionPane.showMessageDialog(null, "Balance:\n" + savingsaccount.getBalance());
- savingsaccount.withdrawl(withdrawAmount);
- savingsaccount.getBalance();
- JOptionPane.showMessageDialog(null, "Updated Balance:\n" + savingsaccount.getBalance());
- } else if (type == 3) {
- studentaccount.getBalance();
- JOptionPane.showMessageDialog(null, "Balance:\n" + studentaccount.getBalance());
- studentaccount.withdrawl(withdrawAmount);
- studentaccount.getBalance();
- JOptionPane.showMessageDialog(null, "Updated Balance:\n" + studentaccount.getBalance());
- }
- }
- }
- void checkBalance(int type){
- if (type == 1){
- currentaccount.getBalance();
- JOptionPane.showMessageDialog(null, "Balance:\n" + currentaccount.getBalance());
- }
- else if (type == 2) {
- String note = JOptionPane.showInputDialog(null,"Do you want to check Balance with Interest?\n(1) Yes\n(0) No");
- int op = Integer.parseInt(note);
- if(op == 0){
- savingsaccount.getBalance();
- JOptionPane.showMessageDialog(null, "Balance:\n" + savingsaccount.getBalance());
- }
- else{
- String year = JOptionPane.showInputDialog(null,"How many years of interest: ");
- int y = Integer.parseInt(year);
- savingsaccount.getBalance(y);
- JOptionPane.showMessageDialog(null, "Balance:\n" + savingsaccount.getBalance(y));
- }
- }
- else if (type == 3) {
- studentaccount.getBalance();
- JOptionPane.showMessageDialog(null, "Balance:\n" + studentaccount.getBalance());
- }
- }
- }
- // BankAccount
- import java.util.Random;
- public abstract class BankAccount {
- private String name;
- private int accountNumber;
- private double accountBalance;
- private double minimumBalance;
- public int accountGenerator(){
- Random rand = new Random();
- return 10000+rand.nextInt(89999);
- }
- BankAccount(){
- name =" ";
- accountBalance = 0.0;
- }
- BankAccount (String name, double balance, double minBalance){
- this.name = name;
- accountBalance = balance;
- minimumBalance = minBalance;
- accountNumber = accountGenerator();
- }
- public void setMemberName(){this.name = name;}
- public String getName(){return name;}
- public void setAccountNumber(){this.accountNumber=accountGenerator();}
- public int getAccountNumber(){return accountNumber;}
- public void setAccountBalance(double accountBalance){this.accountBalance=accountBalance;}
- public double getAccountBalance(){return accountBalance;}
- public void setMinimumBalance(){this.minimumBalance=minimumBalance;}
- public double getMinimumBalance(){return minimumBalance;}
- public void deposit(double amount){
- accountBalance+= amount;
- }
- public abstract void withdrawl(double amount);
- public double getBalance(int year){
- return accountBalance;
- }
- public double getBalance(){
- return accountBalance;
- }
- }
- // SavingsAccount
- import javax.swing.JOptionPane;
- public class SavingsAccount extends BankAccount{
- private double interest = 0.05;
- private double maxWithdrawlAmount = 1000000;
- public SavingsAccount(String name, double balance, double minBalance){
- super(name,balance,minBalance);
- }
- SavingsAccount(){
- getName();
- getAccountBalance();
- }
- public void setInterest(){this.interest=interest;}
- public double getInterest(){return interest;}
- public void setMaxWithdrawlAmount(){this.maxWithdrawlAmount=maxWithdrawlAmount;}
- public double getMaxWithdrawlAmount(){return maxWithdrawlAmount;}
- public double getBalance(int year){
- double amount = (getAccountBalance() + interest * getAccountBalance())*year;
- return amount;
- }
- public void withdrawl(double amount){
- if((getAccountBalance() - amount)>= getMinimumBalance()){
- setAccountBalance(getAccountBalance() -amount);
- }
- else{
- JOptionPane.showMessageDialog(null,"Balance cannot be withdrawn!");
- }
- }
- public double getBalance(){
- return getAccountBalance();
- }
- }
- //CurrentAccount
- import javax.swing.JOptionPane;
- public class CurrentAccount extends BankAccount {
- private int tradeLicenceNumber;
- public CurrentAccount(String name,int tradeLicence, double balance, double minBalance){
- super(name,balance,minBalance);
- tradeLicenceNumber = tradeLicence;
- }
- CurrentAccount(){
- getName();
- getAccountBalance();
- }
- public void setTradeLicenceNumber(){this.tradeLicenceNumber=tradeLicenceNumber;}
- public int getTradeLicenceNumber(){return tradeLicenceNumber;}
- public void withdrawl(double amount){
- if((getAccountBalance() - amount)>= getMinimumBalance()){;
- setAccountBalance(getAccountBalance()-amount);
- }
- else{
- JOptionPane.showMessageDialog(null,"Balance cannot be withdrawn!");
- }
- }
- public double getBalance(){
- return getAccountBalance();
- }
- }
- //StudentAccount
- import javax.swing.JOptionPane;
- public class StudentAccount extends BankAccount{
- private String institutionName;
- public StudentAccount(String name, String institute, double balance, double minBalance){
- super(name,balance,minBalance);
- institutionName = institute;
- }
- StudentAccount(){
- getName();
- getAccountBalance();
- }
- public void setInstitutionName(){this.institutionName=institutionName;}
- public String getInstitutionName(){return institutionName;}
- public void withdrawl(double amount){
- if(amount<=20000){
- if((getAccountBalance() - amount)>= getMinimumBalance()){
- setAccountBalance(getAccountBalance() - amount);
- }
- else{
- JOptionPane.showMessageDialog(null,"Balance cannot be withdrawn!");
- }
- }
- else{
- JOptionPane.showMessageDialog(null,"Balance exceeds limit of withdrawl!");
- }
- }
- public double getBalance(){
- return getAccountBalance();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement