Question #31169

suggest a business application that employs inheritance. Predict the classes and subclasses that may be involved and support your prediction.
1

Expert's answer

2013-06-07T07:21:10-0400

So let's create superclass BusinessCompany that has two instance variables: name, numOfWorkers and one method profit(...):


class BusinessCompany {
    String name;
    int numOfWorkers;
    public double profit(double x) {
        double m = Math.pow(x, 2);
        return m;
    }
}


Let's create three subclasses: Company1, Company2, Company3. These three classes have their names, number of workers and functions of profit growth. Company1 and Company 3 have equal functions of profit growth: x2x^2 (such as BusinessCompany), for example, let's xx – number of orders:

So Company1:


class Company1 extends BusinessCompany {
    String name = "Adaptec";
    int numOfWorkers = 143;
}


Company3:


class Company3 extends BusinessCompany {
    String name = "Adobe Systems";
    int numOfWorkers = 1175;
}


Company2 has another function of profit growth x4x^4. Method profit() should be overridden by this subclass:


class Company2 extends BusinessCompany {
    String name = "AECOM";
    int numOfWorkers = 171;
    public double profit(double x) {
        double m = Math.pow(x, 4);
        return m;
    }
}


So we have superclass and three subclasses. Every subclass can use instance variables and methods of superclass. And let's create a main class:


class MainC {
    public static void main(String[] args) {
        Company1 A = new Company1();
        Company2 B = new Company2();
        Company3 C = new Company3();
        System.out.println(A.name+"; "+A.numOfWorkers+"; "+A.profit(32));
        System.out.println(B.name+"; "+B.numOfWorkers+"; "+B.profit(12));
        System.out.println(C.name+"; "+C.numOfWorkers+"; "+C.profit(22));
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS