Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.batch5.account;
- import com.batch5.randomgenerator.*;
- public class Account {
- private String memberName;
- private String accountNumber;
- private double accountBalance;
- RandomNumber random= new RandomNumber();
- Account(){}
- Account(String memberName, double accountBalance)
- {
- this.memberName=memberName;
- this.accountBalance=accountBalance;
- accountNumber=random.RandomGenerator();
- }
- public String getMemberName() {
- return memberName;
- }
- public String getAccountNumber() {
- return accountNumber;
- }
- public double getAccountBalance() {
- return accountBalance;
- }
- public void setMemberName(String memberName) {
- this.memberName = memberName;
- }
- public void setAccountBalance(double accountBalance) {
- this.accountBalance = accountBalance;
- }
- //---------------------------------------------------------------------------------------//
- public double withdraw(double amount)
- {
- accountBalance-=amount;
- return accountBalance;
- }
- public double deposit()
- {
- return accountBalance;
- }
- public void accountInfo()
- {
- System.out.println("Account number is="+ accountNumber);
- }
- }
- -----------------------------------------------------------------
- package com.batch5.account;
- import com.batch5.randomgenerator.*;
- public class Account {
- private String memberName;
- private String accountNumber;
- private double accountBalance;
- RandomNumber random= new RandomNumber();
- Account(){}
- Account(String memberName, double accountBalance)
- {
- this.memberName=memberName;
- this.accountBalance=accountBalance;
- accountNumber=random.RandomGenerator();
- }
- public String getMemberName() {
- return memberName;
- }
- public String getAccountNumber() {
- return accountNumber;
- }
- public double getAccountBalance() {
- return accountBalance;
- }
- public void setMemberName(String memberName) {
- this.memberName = memberName;
- }
- public void setAccountBalance(double accountBalance) {
- this.accountBalance = accountBalance;
- }
- //---------------------------------------------------------------------------------------//
- package com.batch5.account;
- import java.util.Scanner;
- public class Bank {
- Bank(){}
- public static void main(String args[])
- {
- Scanner in= new Scanner(System.in);
- String accountHolderName;
- double initialBalance;
- String choice2;
- System.out.println("Welcome to Nucleus batch 5 banking system.......");
- System.out.println("Do you want to open an account ?(Y/N)");
- String choice1=in.next();
- if(choice1.equals("Y"))
- {
- System.out.println("Enter account holder name:");
- accountHolderName=in.next();
- System.out.println("Enter initial balance");
- initialBalance=in.nextDouble();
- System.out.println("What type of account you want to create(Savings(S)/Current(C):");
- choice2=in.next();
- if(choice2.equals("S"))
- {
- Account account= new Account(accountHolderName,initialBalance);
- Account savingAccount=new SavingAccount(10000.00,500.00);
- account.accountInfo();
- System.out.println("Press [1] to DEPOSIT , Press [2] to WITHDRAW , " +
- "Press [3] to DISPLAY BALANCE , Press [0] to EXIT....)");
- int choice3=in.nextInt();
- switch(choice3)
- {
- case 1:
- System.out.println("Enter amount to be deposited");
- double addAmount=in.nextDouble();
- System.out.println("Deposit add with interest ! Do you want to check balance ?(y/n)");
- String internalChoice1=in.next();
- if(internalChoice1.equals("Y"))
- System.out.println(savingAccount.getbalance());
- else
- savingAccount.getbalance();
- }
- }
- }
- }
- }
- --------------------------------------------------------------------
- package com.batch5.account;
- public class CurrentAccount extends Account {
- String tradeLicenseNumber;
- Account account = new Account();
- public CurrentAccount() {
- // TODO Auto-generated constructor stub
- }
- public CurrentAccount(String tradeLicenseNumber)
- {
- this.tradeLicenseNumber=tradeLicenseNumber;
- }
- public String getTradeLicenseNumber() {
- return tradeLicenseNumber;
- }
- public void setTradeLicenseNumber(String tradeLicenseNumber) {
- this.tradeLicenseNumber = tradeLicenseNumber;
- }
- //---------------------------------------------------------------------------------------//
- public double getbalance()
- {
- return account.getAccountBalance();
- }
- @Override
- public double withdraw(double amount)
- {
- if(account.getAccountBalance()>account.getAccountBalance())
- {
- account.setAccountBalance(account.getAccountBalance()-amount);
- return account.getAccountBalance();
- }
- else
- {
- System.out.println("More than balance available amount entered");
- return 0;
- }
- }
- }
- ---------------------------------------------------
- package com.batch5.account;
- public class SavingAccount extends Account {
- private double interest,withdraw_limit,minBalance;
- //Account account= new Account();
- SavingAccount()
- {
- super();
- }
- SavingAccount(double withdraw_limit,double minBalance)
- {
- //super();
- interest=0.05;
- this.withdraw_limit=withdraw_limit;
- this.minBalance=minBalance;
- }
- public double getInterest() {
- return interest;
- }
- public double getWithdraw_limit() {
- return withdraw_limit;
- }
- public void setInterest(double interest) {
- this.interest = interest;
- }
- public void setWithdraw_limit(double withdraw_limit) {
- this.withdraw_limit = withdraw_limit;
- }
- public double getMinBalance() {
- return minBalance;
- }
- public void setMinBalance(double minBalance) {
- this.minBalance = minBalance;
- }
- //---------------------------------------------------------------------------------------//
- /*public double savingInfo()
- {
- }*/
- public double getbalance()
- {
- return account.getAccountBalance()*interest+account.getAccountBalance();
- }
- @Override
- public double withdraw(double withdraw_amount)
- {
- if((withdraw_amount>withdraw_limit))
- {
- System.out.println("Overflow");
- return 0;
- }
- else
- {
- if((account.getalance()-withdraw_amount)<minBalance)
- {
- System.out.println("underflow !!");
- return 0;
- }
- else
- return account.getAccountBalance()-withdraw_amount;
- }
- }
- }
- --------------------------------------------------------------------
- package com.batch5.randomgenerator;
- import java.util.Random;
- public class RandomNumber {
- String number;
- //RandomNumber(){}
- public String RandomGenerator()
- {
- Random rand = new Random();
- number ="" + rand.nextInt(10) + rand.nextInt(10)+ rand.nextInt(10)+
- rand.nextInt(10)+ rand.nextInt(10);
- return number;
- }
- }
Add Comment
Please, Sign In to add comment