Skip to content

daniillaureanti-java/figures

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Figures

The purpose of this exercise is to train you to work with classes, methods and inheritance.

Estimated workload of this exercise is 60 min.

Description

Please, make Triangle, Quadrilateral, Circle classes extend Figure abstract class.

Implement methods in Triangle, Quadrilateral, Circle:

  1. constructors with following parameters:

    • Triangle - three vertices (points) as parameters.
    • Quadrilateral - four vertices (points) as parameters.
    • Circle - point of the center and double value of the radius.

    All the input datasets in tests are guaranteed to form a non-degenerative figures. For Quadrilaterals, it is guaranteed that all test datasets would form a convex quadrilaterals.

  2. public double area()
    Return the area of the figure.
    Note: Convex quadrilaterals can be divided into two triangles by any of their diagonals.

  3. public String pointsToString()
    Return a String value in following formats:

    • Triangle -
      • Format: (a.x,a.y)(b.x,b.y)(c.x,c.y)
      • Example: (0.0,0.0)(0.1,5.8)(7.0,7.0)
    • Quadrilateral -
      • Format: (a.x,a.y)(b.x,b.y)(c.x,c.y)(d.x, d.y)
      • Example: (0.0,0.0)(0.0,7.1)(7.0,7.0)(7.0,0.0)
    • Circle -
      • Format: (center.x,center.y)
      • Example: (0.0,0.6)

    Note:: you may benefit from implementing toString() in the Point class

  4. public String toString()
    Return a String value in following formats:

    • Triangle -
      • Format: Triangle[(a.x,a.y)(b.x,b.y)(c.x,c.y)]
      • Example: Triangle[(0.0,0.0)(0.1,5.8)(7.0,7.0)]
    • Quadrilateral -
      • Format: Quadrilateral[(a.x,a.y)(b.x,b.y)(c.x,c.y)(d.x, d.y)]
      • Example: Quadrilateral[(0.0,0.0)(0.0,7.1)(7.0,7.0)(7.0,0.0)]
    • Circle -
      • Format: Circle[(center.x,center.y)radius]
      • Example: Circle[(0.0,0.6)4.5]

    Note: you may use default implementation given in the Figure class, when it suits a case well.

  5. public Point leftmostPoint()
    Return a leftmost point of the figure: the one having the least X coordinate.
    If there are many leftmost points, return any of them.

Point class is already there.

Hints:

Examples

You may use Main class to try your code. There are some examples below.


Sample code:

...
double area = new Triangle(new Point(0,0), new Point(3, 0), new Point(0, 4)).area();
System.out.println(area);

Output:

6

Sample code:

...
double area = new Quarilateral(new Point(1,0), new Point(2, 1), new Point(1, 2), new Point(0, 1)).area();
System.out.println(area);

Output:

2

Sample code:

...
double area = new Circle(new Point(1,1), 3).area();
System.out.println(area);

Output:

28.274333882308138

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages