Untitled

mail@pastecode.io avatar
unknown
java
2 years ago
3.9 kB
2
Indexable
Never
public static void main(String[] args)
    {
        int choice=0;
        
        String name,bank;
        try (Scanner scan = new Scanner(System.in))
        {
            while (true) 
            {
                System.out.println("Creating Account");
                System.out.print("Greetings, Which Account would you like to open?\n[1-Saving Account]\n[2-Current Account]\nEnter Here: ");
                choice=scan.nextInt();
                System.out.print("Insert your name: ");
                scan.nextLine();
                name= scan.nextLine();
                System.out.print("Insert your Bank name: ");
                bank= scan.nextLine();
                if(choice==1)
                {
                    SavingAccount saveaccount = new SavingAccount();    
                    saveaccount= new SavingAccount(name,bank);
                    System.out.println(saveaccount);    
                }
                if(choice==2)
                {
                    CurrentAccount currentAccount = new CurrentAccount();    
                    currentAccount= new CurrentAccount(name,bank);
                    System.out.println(currentAccount);    
                }
                
                System.out.print("\nWould you like to continue? [1- Yes || 0-No]\nEnter Here: ");
                choice=scan.nextInt();
                if(choice == 0)
                    break; 
            }
        }    
    }
        
}

class BankAccount
{
    protected String fullName, BankName,accType;
    protected int accountNumber;
    protected Double interestRate, balance;

    public BankAccount(String fullName, String bankName) {
        this.fullName = fullName;
        BankName = bankName;
        
    }
   
    public BankAccount() {
    }

    public String getFullName() {
        return fullName;
    }
    public void setFullName(String fullName) {
        this.fullName = fullName;
    }
    public String getBankName() {
        return BankName;
    }
    public void setBankName(String bankName) {
        BankName = bankName;
    }
    public int getAccountNumber() {
        return accountNumber;
    }
    public void setAccountNumber(int accountNumber) {
        this.accountNumber = accountNumber;
    }
    public String getAccType() {
        return accType;
    }
    public void setAccType(String accType) {
        this.accType = accType;
    }
    public Double getInterestRate() {
        return interestRate;
    }
    public void setInterestRate(Double interestRate) {
        
        this.interestRate = interestRate;
    }
    public Double getBalance() {
        return balance;
    }
    public void setBalance(Double balance) {
        
        this.balance = balance;
    }

    @Override
    public String toString() {
        return "\nYour Details \nfullName=" + fullName + "\nBankName=" + BankName + "\naccountNumber=" + accountNumber
                + "\naccType=" + accType + "\ninterestRate=" + interestRate + "\nbalance=" + balance ;
    }
}

class SavingAccount extends BankAccount 
{

    double Newbalance=50;
    double NewinterestRate = 0.0005;

    public SavingAccount(){
       super();
    }

    public SavingAccount(String name, String BankName){
        
        super(name, BankName);
        this.setBalance(Newbalance);
        this.setInterestRate(NewinterestRate);
        this.setAccType("Saving Account");
    }
}

class CurrentAccount extends BankAccount 
{

    double Newbalance=200;
    double NewinterestRate = 0.0001;

    public CurrentAccount(){
        super();
    }

    public CurrentAccount(String name, String BankName)
    {
        super(name, BankName);
        this.setBalance(Newbalance);
        this.setInterestRate(NewinterestRate);
        this.setAccType("Current Account");
    }
   
}