The final code looks like this. Fixed the errors and understood the concepts of inheritance. Thanks to you guys who responded to my post. Your replies were helpful.
Account Class
public class Account {
String name;
String number;
public double balance;
public class Account
{
public String acctnum;
public String accttitle;
public Double acctbal;
public String accttitle2;
public Account()
{
}
public void withdraw(Double amount)
{
acctbal=acctbal-amount;
}
public void deposit(Double amount)
{
acctbal=acctbal+amount;
}
public double zakat() /*In Islam Zakat is deducted every year from saving
accounts in holy month of Ramadan */
{
Double z=acctbal*0.025;
return z;
}
public void showdetail()
{
System.out.println("The Account Number ="+acctnum);
System.out.println("The Account Title ="+accttitle);
System.out.println("The Account Balance ="+acctbal);
}
}
Current Account Class
public class CurrentAccount extends Account
{
public CurrentAccount(String Num,String Title,double Bal)
{
acctnum = Num;
accttitle = Title;
acctbal = Bal;
}
public double tax()
{
double t= acctbal*0.05;
return t;
}
}
Joint Account Class
public class JointAccount extends Account
{
public String accttitle2;
public JointAccount(String Num,String Title,String accttitle_1,double Bal)
{
acctnum = Num;
accttitle=Title;
accttitle2=accttitle_1;
acctbal =Bal;
}
public void showdetail() //Overrding
{
System.out.println("The Account Number = " + acctnum);
System.out.println("The Account Title = " + accttitle + " and " + accttitle2);
System.out.println("The Account Balance = " + acctbal);
}
public double calculatetax()
{
double t= acctbal*0.09;
return t;
}
}
SavingAccount Class
public class savingAccount extends Account
{
public savingAccount(String Num,String Title,Double Bal)
{
super.acctnum =Num;
super.accttitle=Title;
super.acctbal =Bal;
}
public double tax()
{
double t= acctbal*0.07;
return t;
}
public void withdraw(double amount)
{
super.withdraw(amount);
if(acctbal<1000){
acctbal=acctbal-150;
}
}
}
Following is testApp class
public class testApp
{
public static void main(String args[])
{
savingAccount obj=new savingAccount("01-102-33","Ali",30000.0);
System.out.println("My Balance is="+obj.acctbal);
obj.withdraw(5000.0);
System.out.println("After Withdraw The Balanc is="+obj.acctbal);
obj.deposit(10000.0);
System.out.println("After deposit balance is ="+obj.acctbal);
double z= obj.zakat();
System.out.println("zakat is="+z);
obj.withdraw(z);
System.out.println("after draw balance is="+obj.acctbal);
double t=obj.tax();
System.out.println("Tax is="+t);
obj.withdraw(t);
System.out.println("Remaining balance is ="+obj.acctbal);
obj.withdraw(25000.0);
obj.showdetail();
CurrentAccount obj1=new CurrentAccount("01-102-33","Ali",10000.0);
System.out.println("My Balance is="+obj1.acctbal);
t=obj1.tax();
System.out.println("Tax is ="+t);
obj1.withdraw(t);
System.out.println("Remaining bal is="+obj1.acctbal);
obj1.showdetail();
JointAccount obj2= new JointAccount("11-101-23","Amjad","Usman",20000.0);
System.out.println("My Balance is="+obj2.acctbal);
t=obj2.calculatetax();
System.out.println("Tax is ="+t);
obj2.showdetail();
}
}