Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hey Java expert, go ahead and modify this code another way to take advantage of the dynamic binding in that code. Write the main method

Hey Java expert, go ahead and modify this code another way to take advantage of the dynamic binding in that code. Write the main method to demonstrate the correct functionality of the additions/modifications. INCLUDE SCREENSHOT OF modified WORKING CODE 


import java.util.Scanner;    //Defining the abstract class that will overide to calculate both areas  abstract class Base   {      //Setting varibales for the arae, length, and height      double l, h, area;            void setDimentions()       {          double length, height;          System.out.println("Enter the length: ");          Scanner s = new Scanner(System.in);          length = s.nextDouble();          System.out.println("Enter the height: ");          height = s.nextDouble();          this.l = length;          this.h = height;      }            abstract void computeArea();   }    //this overrides the computeArea() method so that it can also be used to calculate the area of triangle  class Triangle extends Base   {      void computeArea()       {          area = (l * h) / 2;          System.out.println("The area of a triangle is = " + this.area);      }  }    //this overrides the computeArea() method so that it can also be used to calculate the area of rectangle  class Rectangle extends Base   {      void computeArea()       {          area = (l * h);          System.out.println("The area of a rectangle is = " + this.area);      }  }    //Uses computeArea() to calculate the two different areas by overriding the methos defined in the Base class  public class Calculator   {      public static void main(String[] args)       {          Triangle t = new Triangle();          Rectangle r = new Rectangle();          System.out.println("Find the area of a triangle");          t.setDimentions();            t.computeArea();            System.out.println("Find the area of rectangle");          r.setDimentions();            r.computeArea();      }  }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Advanced Accounting in Canada

Authors: Hilton Murray, Herauf Darrell

8th edition

1259087557, 1057317623, 978-1259087554

More Books

Students also viewed these Operating System questions