Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

//as per Q7 of ISC-2022 sem2

class Item
{
String name;
int code;
double amount;
//parameterised constructor
Item(String a, int b, double c)
{
name=a;
code=b;
amount=c;
}
void show()
{
System.out.println("Item name is...."+name);
System.out.println("Item code is...."+code);
System.out.println("Amount is...."+amount);
}
}//end of base class

--------------------------------X--------------------------------------

//as per Q7 of ISC-2022 sem2


import java.util.*;
class Taxable extends Item
{
double tax;
double totamt;
//parameterised constructor
Taxable(String aa, int bb, double cc)
{
super(aa,bb,cc);//invoking base class constructor
tax=totamt=0.0;
}
void cal_tax()
{
tax=amount*10.2/100.0;
totamt=amount+tax;
}
void show() //show() overridden function
{
super.show();
System.out.println("Tax amount is...."+tax);
System.out.println("Total amount is...."+totamt);
}
static void main()
{
//taking inputs of base class data
Scanner ab=new Scanner(System.in);
System.out.print("Enter Item name :");
String a=ab.nextLine();
System.out.print("Enter Item code :");
int b=ab.nextInt();
System.out.print("Enter Item cost :");
double c=ab.nextDouble();
//creating an object of child class
Taxable obj=new Taxable(a,b,c);
obj.cal_tax();
obj.show();
}
}//end of base class

/*
OUTPUT
Enter Item name :Mobile
Enter Item code :1099
Enter Item cost :13000

Item name is....Mobile


Item code is....1099
Amount is....13000.0
Tax amount is....1326.0
Total amount is....14326.0

*/

You might also like