Inheritance
The following question has been taken from last year board exam. In this question student has to create a child class named as Sales in which their will be variables and functions that will get and set the values of the data members and will be used accordingly.
Solution for the above question is given below:
public class Sales extends Product
{
private int day;
double tax, totamt;
public Sales(String n, int c, double p, int d, double ta)
{
super(n,c,p);
day=d;
tax=12.4;
totamt=ta;
}
public void compute()
{
System.out.print("Input number of days: ");
day=new java.util.Scanner(System.in).nextInt();
double fine=0.0;
if(day>30)
{
fine=2.5*amount;
}
tax=12.4*amount;
totamt=amount+tax+fine;
}
public void show()
{
super.show();
System.out.println("Total amount is "+totamt);
}
}
No comments:
Post a Comment