Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package day2;
- import java.util.Random;
- import java.util.Scanner;
- public class Q3 {
- public static void main(String[] args)
- {
- Scanner scanner=new Scanner(System.in);
- System.out.println("enter the account name");
- String name=scanner.next();
- System.out.println("what type of account do u open press 1 for saving account and press 2 for cuurent account");
- int n=scanner.nextInt();
- System.out.println("enter initial balance");
- //System.out.println(5+10);
- double balance=scanner.nextDouble();
- double bal=balance+ 5.0/100*balance;
- //System.out.println(bal);
- if(n==1){
- SavingAccount savingaccount=new SavingAccount(name, bal);
- //savingaccount.setAccountBalance();
- System.out.println("enter 1 for deposit money, 2 for withdraw money, 3 for display the account balance");
- int c=scanner.nextInt();
- switch(c){
- case 1:
- System.out.println("enter money to deposit");
- double deposit=scanner.nextDouble();
- savingaccount.deposit(deposit);
- savingaccount.display();
- break;
- case 2:
- System.out.println("enter money to withdraw");
- double withdraw=scanner.nextDouble();
- savingaccount.withdraw(withdraw);
- savingaccount.display();
- break;
- case 3:
- savingaccount.display();
- break;
- }
- }
- if(n==2){
- CurrentAccount currentaccount=new CurrentAccount(name,balance);
- System.out.println("enter 1 for deposit money, 2 for withdraw money, 3 for display the account balance");
- int c1=scanner.nextInt();
- switch(c1){
- case 1:
- System.out.println("enter money to deposit");
- double deposit=scanner.nextDouble();
- currentaccount.deposit(deposit);
- currentaccount.display();
- break;
- case 2:
- System.out.println("enter money to withdraw");
- double withdraw=scanner.nextDouble();
- currentaccount.withdraw(withdraw);
- currentaccount.display();
- break;
- case 3:
- currentaccount.display();
- break;
- }
- //account.display();
- scanner.close();
- }
- }
- }
- class SavingAccount extends Account {
- //private int mainterest = 5;
- //private double maximumWithdrawAmount;
- public SavingAccount(String accountHolderName, double accountBalance)
- {
- super(accountHolderName, accountBalance,"");
- }
- void getBalance() {
- }
- void deposit(double deposit) {
- super.setAccountBalance((super.getAccountBalance() + deposit));
- }
- void withdraw(double deposit) {
- if (super.getAccountBalance() > deposit) {
- super.setAccountBalance((super.getAccountBalance() - deposit));
- } else {
- System.out
- .println("balance can not be exceed than account balance");
- }
- }
- }
- class CurrentAccount extends Account {
- int tradeLicenseNumber;
- public CurrentAccount(String accountHolderName, double accountBalance)
- {
- super(accountHolderName, accountBalance,"");
- }
- void deposit(double deposit) {
- super.setAccountBalance((super.getAccountBalance() + deposit));
- }
- void withdraw(double deposit) {
- if (super.getAccountBalance() > deposit) {
- super.setAccountBalance((super.getAccountBalance() - deposit));
- } else {
- System.out
- .println("balance can not be exceed than account balance");
- }
- }
- }
- class Account {
- // private string accountNumber;
- private String accountHolderName;
- private double accountBalance;
- private String accountNumber;
- public Account()
- {
- }
- public Account(String accountHolderName, double accountBalance,String accountNumber) {
- Random rand = new Random();
- this.accountNumber = accountNumber + rand.nextInt(10)
- + rand.nextInt(10) + rand.nextInt(10) + rand.nextInt(10)
- + rand.nextInt(10);
- this.accountHolderName = accountHolderName;
- this.accountBalance = accountBalance;
- }
- public String getAccountHolderName() {
- return accountHolderName;
- }
- public double getAccountBalance() {
- return accountBalance;
- }
- public String getAccountNumber() {
- return accountNumber;
- }
- public void setAccountBalance(double accountBalance) {
- this.accountBalance = accountBalance;
- }
- void display() {
- System.out.println(this.getAccountHolderName());
- System.out.println(this.getAccountNumber());
- System.out.println(this.getAccountBalance());
- }
- }
Add Comment
Please, Sign In to add comment