Q2. Write a program (Abstract+Interface) Define a class named Point containing: Two private instance variables x and y of type int. A full parametrized constructor Getters for all instance variables Define an abstract class named Shape containing: An instance variable named s of type Point. A full parametrized constructor A method named getS that returns the value of instance variable An abstract method named Area that has a return type double. Define an interface named Printable containing a method print without parameters and returning void. Define a class named Rectangle which is extended from class Shape, implements the interface printable and containing: Three instance variables named Length, Width of type int and an instance variable named d of type Point. A constructor with two parameters of type Point which initializes all the instance variables. The lengthis the difference in y-coordinates of any top and bottom point.  length= Math.abs(s.getY()-d.getY()); The widthis the difference in x-coordinates of any left and right point. width= Math.abs(s.getX()-d.getX());   An overridden method named Area which returns the calculated area of the rectangle. An overridden method named print which print the pattern of a rectangle using the ‘*’ character according to the length and the width. Define a class named Line which implements the interface printable and containing: Two instance variables named start and end of type Point. A constructor with two parameters of type Point which initializes all the instance variables. A method getLength returning the length of a line ( The distance between start and end). Math.sqrt(Math.pow(start.getX()-end.getX(),2)+Math.pow(start.getY()-end.getY(),2))   An overridden method named print which print the pattern of a line using the ‘*’ character according to the length of the line. Define a class named Text which implements the interface printable and containing:

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Q2. Write a program (Abstract+Interface)

Define a class named Point containing:

  • Two private instance variables x and y of type int.
  • A full parametrized constructor
  • Getters for all instance variables

Define an abstract class named Shape containing:

  • An instance variable named s of type Point.
  • A full parametrized constructor
  • A method named getS that returns the value of instance variable
  • An abstract method named Area that has a return type double.

Define an interface named Printable containing a method print without parameters and returning void.

Define a class named Rectangle which is extended from class Shape, implements the interface printable and containing:

  • Three instance variables named Length, Width of type int and an instance variable named d of type Point.
  • A constructor with two parameters of type Point which initializes all the instance variables.
  • The lengthis the difference in y-coordinates of any top and bottom point.

 length= Math.abs(s.getY()-d.getY());

  • The widthis the difference in x-coordinates of any left and right point.

width= Math.abs(s.getX()-d.getX());

 

  • An overridden method named Area which returns the calculated area of the rectangle.
  • An overridden method named print which print the pattern of a rectangle using the ‘*’ character according to the length and the width.

Define a class named Line which implements the interface printable and containing:

  • Two instance variables named start and end of type Point.
  • A constructor with two parameters of type Point which initializes all the instance variables.
  • A method getLength returning the length of a line ( The distance between start and end).

Math.sqrt(Math.pow(start.getX()-end.getX(),2)+Math.pow(start.getY()-end.getY(),2))

 

  • An overridden method named print which print the pattern of a line using the ‘*’ character according to the length of the line.

Define a class named Text which implements the interface printable and containing:

  • One instance variables named Content of type String.
  • A full parametrized constructor.
  • An overridden method named print which print the text.

Define a third class named TestDemo contains a main method that test the functionality of the above classes.

-define 2 object from class point p1 and p2, p1=(2,4),p2=(9,14).

-define arrayList of type printable, the first element is object from class Rectangle, the second element is object from class Line and the third element is an object from class Text.

- call the method print to print all the elements of the arrayList.

 

Output:

 

**********

**********

**********

**********

**********

**********

**********

This is a printable text

*************

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education