मराठी

A super class Item has been defined to store the details of an item sold by a wholesaler to a retailer. Define a subclass Taxable to compute the total amount paid by retailer along with service tax. - Computer Science (Theory)

Advertisements
Advertisements

प्रश्न

A super class Item has been defined to store the details of an item sold by a wholesaler to a retailer. Define a subclass Taxable to compute the total amount paid by retailer along with service tax.

Some of the members of both the classes are given below:

Class name: Item
Data members/instance variables:  
name: to store the name of the item
code: integer to store the item code
amount: stores the total sale amount of the item (in decimals)
Member functions/methods:  
Item(.....): parameterized constructor to assign value to the data members
void show(): to display the item details
Class name: Taxable
Data members/instance variables:  
tax: to store the service tax (in decimals)
totamt: to store the total amount (in decimals)
Member functions/methods  
Taxable(.....): parameterized constructor to assign values to the data members of both classes
void cal_tax(): calculates the service tax @ 10.2% of the total sale amount
calculates the total amount paid by the retailer as (total sale amount + service tax)
void show(): to display the item details along with the total amount

Assume that the super class Item has been defined. Using the concept of inheritance, specify the class Taxable, giving details of the constructor, void cal_tax() and void show().

The super class, main function and algorithm need NOT be written.

कोड लेखन
Advertisements

उत्तर

class Taxable extends Item
{
    double tax;
    double totamt;
    public Taxable(tx,tamt,Itemnm,Itcode,Samt)
    {
      tax=tx;
      totamt=tamt;
      super(Itemnm,Itcode,Samt);
    }
    public void cal_tax()
    {
      tax=(amount*10.2)/100;
      totamt=tax+amount;
    }
    public void show()
    {
      super.show();
      System.out.println("Tax :" + tax);
      System.out.println("Total amount :" + totamt);
    }
}
shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
2021-2022 (March) Official Board Paper
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×