Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 // I NEED INHERITENCE THIS PROGRAME 2 // THIS IS SET POINT 3 public class Point 4 { 5 private int x; 6 private

1 // I NEED INHERITENCE THIS PROGRAME 2 // THIS IS SET POINT 3 public class Point 4 { 5 private int x; 6 private int y; 7 8 // Constructor 9 Point() 10 { 11 setPoint(0, 0); 12 } 13 14 // Construtor with parameters 15 public Point(int x, int y) 16 { 17 setPoint(x, y); 18 } 19 20 public void setPoint(int x, int y) // To set points 21 { 22 this.x = x; 23 this.y = y; 24 } 25 26 int getXPoint() 27 { 28 return this.x; 29 } 30 31 int getYPoint() 32 { 33 return this.y; 34 } 35 36 public void displayPoint() 37 { 38 System.out.println(" Point x is: " + getXPoint() + "Point y is: " + getYPoint()); 39 } 40 41 42 }

// THIS IS DEMO1 CIRCLE

1 public class Circle extends Point 2 { 3 private double r; 4 5 /*public void setRadius() 6 { 7 this(0.0); 8 } 9 */ 10 public void setRadius(double r) 11 { 12 //super(r); 13 this.r = r; 14 } 15 16 public double getRadius() 17 { 18 19 return this.r; 20 } 21 22 public double getArea() 23 { 24 return Math.PI * Math.pow(this.r, 2); 25 } 26 27 public double getCircum() 28 { 29 return 2 * Math.PI * r; 30 31 } 32 33 // @Override 34 public String toSting() 35 { 36 String msg = String.format("r=%f", r); 37 return msg; 38 } 39 40 41 42 }

// THIS IS DEMO2 CYLINDER

1 public class Cylinder extends Circle 2 { 3 private double h; 4 5 // Constructor 6 public Cylinder() 7 { 8 this(1.0); 9 } 10 11 public Cylinder(double h) 12 { 13 this.h = h; 14 } 15 // Constructor with parameters 16 public Cylinder(double h, double x, int y, double r) 17 { 18 //super(r); 19 this.h = h; 20 } 21 22 public double getVolume() 23 { 24 return super.getArea() * h; 25 } 26 // @Override 27 public double getSurface() 28 { 29 return 2 * super.getArea() + super.getCircum() * h; 30 31 } 32 33 public String toString() 34 { 35 String msg = String.format(" r = ", getRadius(), this.h); 36 return msg; 37 } 38 39 40 }

// THIS IS TEST DATA

1 public class Test 2 { 3 4 public static void main(String []args) 5 6 { 7 //Point point = new Point(7, 11); 8 //Circle circle = new Circle(22, 8, 3.5); 9 /*Cylinder cylinder = new Cylinder(10, 10, 10, 3.3); 10 11 point.displayPoint(); 12 circle.displayCircle(); 13 circle.displayCircleArea(); 14 circle.calculateCircumference(); 15 cylinder.areaCylinder(); 16 cylinder.volumeCylinder();*/ 17 18 Circle cl = new Circle(); 19 //cl.getRadius(); 20 Cylinder cl2 = new Cylinder(); 21 22 System.out.println(cl); 23 System.out.println(cl2); 24 double a = cl2.getArea(); 25 System.out.println(a); 26 } 27 28 }

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

Database Security

Authors: Alfred Basta, Melissa Zgola

1st Edition

1435453905, 978-1435453906

More Books

Students also viewed these Databases questions

Question

Describe the factors influencing of performance appraisal.

Answered: 1 week ago

Question

List at least three disadvantages to using a consultant.

Answered: 1 week ago

Question

How are arbitrators credentialed?

Answered: 1 week ago