Answer to Question #270594 in Java | JSP | JSF for Shan

Question #270594

Create a parent class “Account” with three variables num, title and bal with two functions withdraw and deposit. Create a child class “SavingAccount” with a function calculateProfit (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 members of Account class. Override withdraw function in SavingAccount to deduct Rs. 250 if the balance after withdrawal of amount is less than 10000.

1
Expert's answer
2021-11-24T00:43:23-0500


public class Main
{
	public static void main(String[] args) {
		SavingAccount s=new SavingAccount();
		s.num=1234;
		s.title="ABC";
		s.bal=0.0;
		s.deposit(5000);
		System.out.println("Profit = "+s.calculateProfit());
		s.withdraw(250);
		System.out.println("Profit = "+s.calculateProfit());
	}
}


class Account{
    public int num;
    public String title;
    public double bal;
    
    public void withdraw(int amount){
        bal=bal-amount;
    }
    public void deposit(int amount){
        bal=bal+amount;
    }
}


class SavingAccount extends Account{
    public double calculateProfit(){
        return (0.075*bal);
    }
    public void withdraw(int amount){
        if((bal-amount)<10000)
            bal=bal-amount;
        System.out.println("You have withdrawn "+amount+". Current balance is "+bal);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS