ISC 2017 Computer Science Question 10 solution - ISC Computer Science Question Paper 2017 Solved

 

ISC 2017 Computer Science Question 10 solution

ISC 2017 Computer Science Question 10 solution - ISC Computer Science Question Paper 2017 Solved

The question as follows:

A superclass Product has been defined to store the details of a product sold by a wholesaler to a retailer. Define a subclass Sales to compute the total amount paid by the retailer with or without a fine along with service tax.

Some of the members of both classes are given below:

Class name: Product

Data members/instance variables:

name: stores the name of the product

code: integer to store the product code

amount: stores the total sale amount of the product (in decimals)

Member functions/methods:

Product (String n, int c, double p): parameterized constructor to assign data members: name = n, code = c and amount = p

void show(): displays the details of the data members

Class name: Sales

Data members/instance variables:

day: stores number of days taken to pay the sale amount

tax: to store the sen ice tax (in decimals)

totamt: to store the total amount (in decimals)

Member functions/methods:

Sales(….): parameterized constructor to assign values to data members of both the classes

void compute(): calculates the service tax @ 12.4% of the actual sale amount

calculates the fine @ 2.5% of the actual sale amount only if the amount paid by the retailer to the wholesaler exceeds 30 days calculates the total amount paid by the retailer as (actual sale amount + service tax + fine)

void show (): displays the data members of the superclass and the total amount

Assume that the superclass Product has been defined. Using the concept of inheritance, specify the class Sales giving the details of the constructor (…), void compute () ) and void show(). The superclass, main function, and algorithm need NOT be written.

Solution:

In the following source code, the Product contains a name, code, and amount with a parameterize constructor and show() method.

class Product

{

    String name;

    int code;

    double amount;

    Product(String n, int c, double p) //Constructor

    {

        name = n;

        code = c;

        amount = p;

    }

 

    void show()

    {

        System.out.println("Name is :"+ name);

        System.out.println("Code is :" + code);

        System.out.println("Total Sale Amount:" + amount);

    }

}

In the following source code the Sales class inherit Product class with day, tax, totamt and find as an instance variable and one parameterize constructor with compute() method where the given condition is done and show() method in which super. show() called with total amount print.

class Sales extends Product {

    int day;

    double tax;

    double totamt;

    double fine = 0.0;

    Sales(String n, int c, double p, int d)

    {

        super(n, c, p);

        day = d;

    }

    // Compute method started 

     void compute()

    {

        if(day <= 30)

        {

            tax = 12.4 * amount /100;

            totamt = amount + tax;

        }

        if(day > 30)

        {

            tax= 12.4 * amount /100;

            fine = 2.5 * amount /100;

            totamt = amount + tax + fine;

        }

    // Compute method ended

 

    void show ()

    {

        super.show();

        System.out.println ("Total amount to be paid::"+ totamt);

    }

     public static void main(String args[])

    {

        Sales ob1=new Sales("Laptop", 1001, 34500.0, 40);

        Sales ob2=new Sales("Printer", 1002, 4500.0, 31);

        ob1.compute();

        ob1.show();

        ob2.compute();

        ob2.show();

    }

}

More Java program



SHARE THIS
Previous Post
Next Post