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
Identify 5 internal and external hardware components of a server
UNO [17]

Answer:

Internal:

#CPU; That retrieves &execute instructions.

#Modem; Modulates& demodulates electric signals.

#RAM;Gives application a place to store &access data on a short time periods.

External:

#Mouse; Transmits commands and controlling movements.

#Moniter; Device used to display video output from computer.

#Printer; Accepts text, graphics to the paper.

Explanation:

Hope this will help you.

5 0
2 years ago
I need help..
labwork [276]

Answer:

which app are u using u should use Android studio or if u are using mac book use xcode

5 0
3 years ago
This function chooses the screen to display based on the score.What is the correct way to call this function?
mario62 [17]

Answer:

checkWin();

Explanation:

its in the code

7 0
3 years ago
Read 2 more answers
5 of 10
DaniilM [7]

Answer:

what

Explanation:

3 0
2 years ago
Given an int variable n that has been initialized to a positive value and, in addition, int variables k and total that have alre
Fudgin [204]

Answer:

The c++ program to implement the while loop is given below.

#include <iostream>

using namespace std;

int main() {

  // declaration of integer variables

   int k, n, total;

   // initialization of integer variables

   k=1, n=4, total=0;

//  loop executed till value of k becomes equal to value of n

   while( k <= n ){

       // cube of every integer is added to the variable total

       total = total + ( k * k * k );

       // value of k is incremented to go to the next number

k = k + 1 ;

   }  

   return 0;

}  

Explanation:

The program begins with the declaration of integer variables.  

int k, n, total;

This is followed by initialization of these variables.

k=1, n=4, total=0;

The while loop runs over the variable k which is initialized to 1. The loop runs till value of k reaches the value of integer n.

First, cube of k is computed and added to the variable total.

After first execution of the loop, total is initialized to the cube of 1.

Next, value of variable k is incremented by 1 so that k is initialized to next integer.

After first execution of the loop, k is incremented from 1 to 2.

while( k <= n )

{

total = total + ( k * k * k );

k = k + 1 ;

   }

When the value of k reaches the value of integer n, the cube of n is calculated and added to the variable, total.

When k is incremented, it becomes more than n and hence, loop gets terminated.

As the return type of main is int, the program terminates with the statement shown below.

return 0;

No output is displayed as it is not mentioned in the question.

No user input is taken as it is mentioned that integer variables are already initialized.

4 0
3 years ago
Other questions:
  • The true or false questions.
    5·1 answer
  • What does zooming do? A. Changes your view of the Frame Editor to be closer or farther away B. Changes your view of the Event Ed
    12·1 answer
  • If after a run of arc consistency during the backtracking search we end up with the filtered domains of *all* of the not yet ass
    12·1 answer
  • What is one reason why a business may want to move entirely online?
    13·1 answer
  • In addition to paying $100 per month for health insurance, sam is responsible for paying her first $500 of medical bills every y
    10·1 answer
  • Another pitfall cited in Section 1.10 is expecting to improve the overall performance of a computer by improving only one aspect
    13·1 answer
  • Find the median and mean of the data set below: 29 17 40 12 29
    6·1 answer
  • If the tax percent is 15% and tax is $36 and percent discount is 10, what is the cost price?​
    12·1 answer
  • When it comes to credit scores, why is having a
    9·1 answer
  • a company recently implemented a secure sockets layer/transport layer security (ssl/tls) version that supports secure hashing al
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!