Answers for "Class inheritance and encapsulation"

0

Class inheritance and encapsulation

public class DPSAccount extends Bank {

        public DPSAccount() {
                super();
        }

        public DPSAccount(String bankName, String address, int numberofBranch) {
                super(bankName, address, numberofBranch);
        }
//      calculateAmount() method.
        public double calculateAmount(double amount) {
                return amount + (4.5/100)*amount;
        }

}
Posted by: Guest on July-11-2021
0

Class inheritance and encapsulation

public class SavingsAccount extends Bank {

        public SavingsAccount() {
                super();
        }

        public SavingsAccount(String bankName, String address, int numberofBranch) {
                super(bankName, address, numberofBranch);
        }
//      calculateAmount() method.
        public double calculateAmount(double amount) {
                return amount + (4/100.0)*amount;
        }

}
Posted by: Guest on July-11-2021
0

Class inheritance and encapsulation

public class Driver {

        

        public static void main(String[] args) {
//              test case.
                SavingsAccount sa = new SavingsAccount("hdfc", "delhi", 10);
                System.out.println("amount: " + sa.calculateAmount(1000));
        }

}
Posted by: Guest on July-11-2021
0

Class inheritance and encapsulation

public class FixedAccount extends Bank {

        public FixedAccount() {
                super();
        }

        public FixedAccount(String bankName, String address, int numberofBranch) {
                super(bankName, address, numberofBranch);
        }
//      calculateAmount() method.
        public double calculateAmount(double amount) {
                return amount + (6/100.0)*amount;
        }

}
Posted by: Guest on July-11-2021
0

Class inheritance and encapsulation

public class Bank {
        private String bankName;
        private String address;
        private int numberOfBranch;
//      default constructor.
        public Bank() {
                bankName = "";
                address = "";
                numberOfBranch = 0;
        }
//      parameterized constructor.
        public Bank(String bankName,String address,int numberofBranch) {
                this.bankName = bankName;
                this.address = address;
                this.numberOfBranch = numberofBranch;
        }
//      getters and setters.
        public String getBankName() {
                return bankName;
        }
        public void setBankName(String bankName) {
                this.bankName = bankName;
        }
        public String getAddress() {
                return address;
        }
        public void setAddress(String address) {
                this.address = address;
        }
        public int getNumberOfBranch() {
                return numberOfBranch;
        }
        public void setNumberOfBranch(int numberOfBranch) {
                this.numberOfBranch = numberOfBranch;
        }
        

}
Posted by: Guest on July-11-2021

Code answers related to "Class inheritance and encapsulation"

Browse Popular Code Answers by Language