1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
storchak [24]
3 years ago
14

Create a Quadrilateral, Oval, Triangle, Polygon class that are all extended from an abstract Shape class (given below). Then ext

end the Quadrilateral class to make a Rectangle class and then extend the Rectangle class to make a Square class. Extend the Oval class to make a Circle class. Extend the Polygon to make a Pentagon and Hexagon classes. These shape classes will contain state information for the object to be drawn.
Computers and Technology
1 answer:
Lostsunrise [7]3 years ago
8 0

Answer:

Shapes.java

public abstract class Shapes {

}

Triangle.java

public abstract class Triangle extends Shapes {

}

IsoscelesTriangle.java

public class IsoscelesTriangle extends Triangle {

double side1;

double side2;

public double getSide1() {

return side1;

}

public void setSide1(double side1) {

this.side1 = side1;

}

public double getSide2() {

return side2;

}

public void setSide2(double side2) {

this.side2 = side2;

}

public IsoscelesTriangle(double side1, double side2) {

super();

this.side1 = side1;

this.side2 = side2;

}

public double perimeter()

{

return 2*side1+side2;

}

public double area()

{

return side1*side2/2;

}

}

EquilateralTriangle.java

public class EquilateralTriangle extends Triangle {

double side;

public EquilateralTriangle(double side) {

super();

this.side = side;

}

public double getSide() {

return side;

}

public void setSide(double side) {

this.side = side;

}

public double perimeter()

{

return 3*side;

}

public double area()

{

return 1.73205*side*side/4;

}

}

Quadrilateral.java

public abstract class Quadrilateral extends Shapes {

}

Rectangle.java

public class Rectangle extends Quadrilateral {

double length;

double breadth;

public double getLength() {

return length;

}

public void setLength(double length) {

this.length = length;

}

public double getBreadth() {

return breadth;

}

public void setBreadth(double breadth) {

this.breadth = breadth;

}

public Rectangle(double length, double breadth) {

super();

this.length = length;

this.breadth = breadth;

}

public double perimeter()

{

return 2*(length+breadth);

}

public double area()

{

return length*breadth;

}

}

Square.java

public class Square extends Quadrilateral {

double side;

public Square(double side) {

super();

this.side = side;

}

public double getSide() {

return side;

}

public void setSide(double side) {

this.side = side;

}

public double perimeter()

{

return 4*side;

}

public double area()

{

return side*side;

}

}

Rhombus.java

public class Rhombus extends Quadrilateral {

double length;

double breadth;

public Rhombus(double length, double breadth) {

super();

this.length = length;

this.breadth = breadth;

}

public double getLength() {

return length;

}

public void setLength(double length) {

this.length = length;

}

public double getBreadth() {

return breadth;

}

public void setBreadth(double breadth) {

this.breadth = breadth;

}

public double perimeter()

{

return 2*(length+breadth);

}

public double area()

{

return length*breadth/2;

}

}

Test.java

import java.util.Scanner;

public class Test {

public static void main(String[] args) {

// TODO Auto-generated method stub

Scanner sc=new Scanner(System.in);

System.out.println("Enter your choice");

System.out.println("1. Create IsoscelesTriangle ");

System.out.println("2. Create EquilateralTriangle");

System.out.println("3. Create Rectangle");

System.out.println("4. Create Square");

System.out.println("5. Create Rhombus");

System.out.println("6. Create Circle");

int choice=sc.nextInt();

switch(choice)

{

case 1:

System.out.println("Enter two sides of triangle");

double side1=sc.nextDouble();

double side2=sc.nextDouble();

IsoscelesTriangle isosceles=new IsoscelesTriangle(side1, side2);

System.out.println("Area of the triangle is "+isosceles.area());

System.out.println("Perimeter of the triangle is "+ isosceles.perimeter());

break;

case 2:

System.out.println("Enter side of the triangle");

double side=sc.nextDouble();

EquilateralTriangle equilateralTriangle=new EquilateralTriangle(side);

System.out.println("Area of the triangle is "+equilateralTriangle.area());

System.out.println("Perimeter of the triangle is "+ equilateralTriangle.perimeter());

break;

case 3:

System.out.println("Enter length and breadth");

double length=sc.nextDouble();

double breadth=sc.nextDouble();

Rectangle rectangle =new Rectangle(length, breadth);

System.out.println("Area of rectangle is "+rectangle.area());

System.out.println("Perimeter of the rectangle is "+rectangle.perimeter());

break;

case 4:

System.out.println("Enter side of the square");

double squareside=sc.nextDouble();

Square square=new Square(squareside);

System.out.println("area of the square is "+square.area());

System.out.println("Perimeter of the square is "+square.perimeter());

break;

case 5:

System.out.println("Enter length and breadth of rhombus");

double rlength=sc.nextDouble();

double rbreadth=sc.nextDouble();

Rhombus rhombus=new Rhombus(rlength, rbreadth);

System.out.println("area of the rhombus is "+rhombus.area());

System.out.println("Perimeter of the rhombus is "+rhombus.perimeter());

break;

case 6:

System.out.println("Enter radius of circle");

double radius=sc.nextDouble();

Circle circle=new Circle(radius);

System.out.println("area of the circle is "+circle.area());

System.out.println("Perimeter of the circle is "+circle.perimeter());

break;

}

}

}

You might be interested in
Help pls<br> cmu cs 0<br> 4.1.2.1 Creating Groups checkpoint 1
Sindrei [870]

Answer:

Explanation:

Circle(centerX, centerY, radius, fill='black', border=None,

borderWidth=2, opacity=100, rotateAngle=0, dashes=False,

align='center', visible=True)

8 0
2 years ago
Read 2 more answers
after installing a secondary hard drive what needs to be done to the hard drive and what do these two task do?
gladu [14]
Keep the first hard drive then override it insert the second one and memory goes into the second one
8 0
3 years ago
Which job role requires you to create user guides for computer products and services?
kipiarov [429]

For plato I think technical writer is the answer.

Technical writer: As a technical writer, you’ll create user manuals and support guides for a number of computer products and services. You may also develop content to market technical products online.

4 0
3 years ago
Read 2 more answers
Which of these graphic elements combine text, illustrations, and color?
Likurg_2 [28]

Answer:

Send the picture.

Explanation:

8 0
3 years ago
Read 2 more answers
Just took a test and I got 5 wrong and I wanted to know the correct answers
baherus [9]

Answer:

I need the pic

Explanation:

7 0
2 years ago
Other questions:
  • Array A is not a heap. Clearly explain why does above tree not a heap? b) Using build heap procedure discussed in the class, con
    15·1 answer
  • Write a main method that prompts the user for an integer between 1 &amp; 10 (inclusive). If the user enters an invalid number, p
    10·1 answer
  • This is a wise and hard question.....What is the hardest question in the world? I know the answer do you?
    10·1 answer
  • 6. Find the volume of the figure. Round your answers to the nearest
    11·1 answer
  • Pls help have absolutely no clue how to delete this
    12·2 answers
  • All banks follow the same guideline for determining if an applicant qualifies for a loan.
    13·1 answer
  • Who was the father of computer?????​
    11·2 answers
  • When you add encryption to a powerpoint presentation what does it do
    14·1 answer
  • Question 4 A data analyst wants to include a line of code directly in their .rmd file in order to explain their process more cle
    10·1 answer
  • Could you tell me the family link app code to unlock a phone please?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!