Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have got this much so far from another question Please find all the Java classes below:- 1. GeometricObject.java public abstract class GeometricObject { public

image text in transcribed

image text in transcribed

image text in transcribed

I have got this much so far from another question

Please find all the Java classes below:-

1. GeometricObject.java

public abstract class GeometricObject {

public abstract double getArea();

public abstract double getPerimeter();

public String toString() {

return "GeometricObject: Area = ?, Perimeter = ? ";

}

}

2. Circle.java

public class Circle extends GeometricObject {

private int radius;

public Circle(int radius) {

super();

this.radius = radius;

}

@Override

public double getArea() {

return Math.PI * Math.pow(radius, 2);

}

@Override

public double getPerimeter() {

return (2 * Math.PI * radius);

}

@Override

public String toString() {

return "Circle: Radius = " + radius + " ,Area = " + getArea() + " ,Perimeter = " + getPerimeter();

}

}

3. GeometricObjectMain.java

import java.io.BufferedReader;

import java.io.InputStreamReader;

public class GeometricObjectMain {

public static void main(String[] args) throws NumberFormatException, Exception {

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter the Radius of the Circle");

int radius = Integer.parseInt(br.readLine());

Circle circleObj = new Circle(radius);

System.out.println(circleObj.toString());

}

}

Inberitance Part 1) Copy the abstract class GeometricObject below, and save it in the file GeometricObjeet.java: // Lab 10 / I Your section> public abstraet class Gecmetricobject public abstract double getArea public abstract double getPerimeter () public String tostring ) return "Gecmetricobject: Area-2, Perimeter- Part 2) Write a subclass of GeometricObject called Circle. Save it in the file Circle java. Include a member variable for the circle's radius. Include a constructor that takes the radius of the cirele as a parameter. Override the getArea0. getPerimeter) and the area and perimeter of the circle. Include a block comment at the top of your class (like the one for GeometriObject above) that gives your name and section number. and toString0 methods. The toString0 method should print out the circle's radius, Hint: the class should start with "public class Circle extends GeometricObjeet" Hint: you can use String format to construct strings in a similar way to System.out.printf. Part 3) Write another subclass of GeometricObjeet called Rectangle. Save it in the file Rectangle java. Include member variables for the width and height of the rectangle. Make a constructor that takes the width and beight as parameters. Finally, override the methods from GeometricObject, similar to what you did with Circle Indude anpropist block comment thetop of your elas. Part 4) Write a third subclass of GeometricObject called EquilateralTriangle. Save it in the file EquilateralTriangle java. Include a member variable for the side length of the triangle, and a constructor that takes the side length as a parameter. Override the methods from GeometricObject. Note that you may wish to use Heron's formula to compute the area of the triangle: hitp:llen.wikipedia ore wiki/Heron's foemula. Inclu

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

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

0123814790, 9780123814791

More Books

Students also viewed these Databases questions

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago