Answer to Question #186093 in Java | JSP | JSF for Hamza

Question #186093

Write a Program that implements Base class calculator and a Derived class scientific calculator, The Derived class should take the basic operations i.e. add, divide, subtract from calculator. However it should have its own methods such as square, cube, and average and display method to display all these calculation for integer numbers. A main class with main method and create an object of base class and call the display method.


1
Expert's answer
2021-04-27T02:11:01-0400
public class Main{
    public static void main(String args[]) {
     Devided calculator=new Devided();
     calculator.display();
     
    }
}
class Base{
     public int add(int firstDigit,int secondDigit){
        return firstDigit+secondDigit;
    }
    public int substract(int firstDigit,int secondDigit){
        return firstDigit-secondDigit;
    }
    public int multiply(int firstDigit,int secondDigit){
        return firstDigit*secondDigit;
    }
    public int divide(int firstDigit,int secondDigit){
        return firstDigit/secondDigit;
    }
    
}
class Devided extends Base{
    public int square(int someDigit){
        return someDigit+someDigit;
    }
    public int cube(int someDigit){
        return someDigit*someDigit*someDigit;
    }
    public int average(int firstDigit,int secondDigit){
        return (firstDigit*secondDigit)/2;
    }
    public void display(){
        Devided calculator=new Devided();
        System.out.println("Add: "+calculator.add(2,3));
        System.out.println("Substract: "+calculator.substract(5,1));
        System.out.println("Multiply: "+calculator.multiply(2,4));
        System.out.println("Devide: "+calculator.divide(12,2));
        System.out.println("Square: "+calculator.square(5));
        System.out.println("Cube: "+calculator.cube(5));
        System.out.println("Average: "+calculator.average(7,9));
    }
}

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!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS