InterviewSolution
| 1. |
A superclass Bank has been defined to store the details of a customer. Define a subclass Account that enables transactions for the customer with the bank. The details of both the classes are given below:Class name: Bank Data members/instance variables: name: stores the name of the customer accno: stores the account number P: stores the principal amount in decimals Member functions/methods: Bank(….): parameterized constructor to assign values to the instance variables void display (): displays the details of the customer Class name: Account Data member/instance variable: amt: stores the transaction amount in decimals Member functions/methods: Account(…): parameterized constructor to assign values to the instance variables of both the classes void deposit(): accepts the amount and updates the principal as p=p+amt void withdraw(): accepts the amount and updates the principal as p=p-amt If the withdrawal amount is more than the principal amount, then display the message “INSUFFICIENT BALANCE”. If the principal amount after withdrawal is less than 500, then a penalty is imposed by using the formula. p=p-(500-p)/10 void display(): displays the details of the customer Assume that the superclass Bank has been defined. Using the concept of Inheritance; specify the class Account giving details of the constructor(…), void deposit(), void withdraw() and void display() The superclass and the main function need not be written. |
|
Answer» import java.util.Date public class Account { private int id=0 private double balance = 0 private static double annualRate = 0 private Date dateCreated = new date(); Account () { id = 0; balance = 0.0; AnnuallnterestRate = 0.0; } public Account (int newId, double newBalance) { id = newld; balance = newBalance; } Account (int newId, double newBalance, double new AnnuallnterestRate) { id = newId; Balance = newBalance; AnnualInterestRate = new AnnualInterestRate; } public int get Id() { return id; } public double get Balance() { return balance; } public double get AnnuallnterestRate() { return AnnuallnterestRate; } double get Monthlylnterest Rate() { return AnnualInterestRate/12/100 + bal; } double withdraw (double amount) { return balance - = amount; } public double withdraw (double amt, date current date, date preset) { if (getBalance() < amount) { System.out.println("Amount is larger than current balance"); if (current date.after (preset) { System.out.printing("Amount exceed balance"); return super; withdraw (amount); } |
|