create a parent class "Account" with three variables num, title and bal with two functions withdraw and deposit. Create a child class "Saving Account" with a function calculate Profit (that applies 7.5% profit on current balance). Finally create the class "TestApp" that creates the object of saving account and call withdraw, deposit functions and public data memebers of account clas. Override withdraw function in savingAccount to deduct Rs:250 if the balance after withdrawal of amount is less than 10000. In javascript
import java.util.Scanner;
public class Account
{
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
SavingAccount sav=new SavingAccount();
System.out.println("Enter the saving acoount amount: ");
sav.num=input.nextInt();
sav.title="ABC";
sav.B=0.0;
System.out.println("Enter the account balance: ");
int n=input.nextInt();
sav.deposit(n);
System.out.println("Profit = "+sav.calculateProfit());
System.out.print("Enter amount to withdraw: ");
int x=input.nextInt();
sav.withdraw(x);
System.out.println("Profit = "+sav.calculateProfit());
}
}
class Account{
public int num;
public String title;
public double B;
public void withdraw(int amount){
B }
public void deposit(int amount){
B=B+amount;
}
}
class SavingAccount extends Account{
public double calculateProfit(){
return (0.075*B);
}
public void withdraw(int amount){
if((B-amount)<10000)
B=B-amount;
System.out.println("You have withdrawn "+amount+", Current balance is "+B);
}
}
Comments
Leave a comment