Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
labSessionFiveToDo1
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
9931069
labSessionFiveToDo1
Commits
aa1ba37e
Commit
aa1ba37e
authored
Apr 23, 2021
by
MostafaRahmati
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
javadoc added
parent
b792a00c
Pipeline
#5953
failed with stages
Changes
5
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
132 additions
and
34 deletions
+132
-34
Circle.java
src/Circle.java
+20
-2
Main.java
src/Main.java
+5
-5
Paint.java
src/Paint.java
+35
-9
Rectangle.java
src/Rectangle.java
+47
-18
Triangle.java
src/Triangle.java
+25
-0
No files found.
src/Circle.java
View file @
aa1ba37e
import
java.util.Objects
;
/**
* class for circle
*/
public
class
Circle
{
private
int
radius
;
/**
* constructor of the circle
* @param radius of the circle
*/
public
Circle
(
int
radius
)
{
this
.
radius
=
radius
;
}
/**
* @return radius of this circle
*/
public
int
getRadius
()
{
return
radius
;
}
/**
* @return perimeter of this circle
*/
public
double
calculatePerimeter
(){
return
2
*
3.14
*
radius
;
}
/**
* @return area of this circle
*/
public
double
calculateArea
(){
return
3.14
*
radius
*
radius
;
}
/**
* @return simulation for drawing a circle
*/
public
void
draw
(){
System
.
out
.
println
(
"Type: Circle\nPerimeter: "
+
calculatePerimeter
()+
"\nArea: "
+
calculateArea
());
System
.
out
.
println
(
"Type: Circle\nPerimeter: "
+
calculatePerimeter
()
+
"\nArea: "
+
calculateArea
());
}
@Override
...
...
src/Main.java
View file @
aa1ba37e
...
...
@@ -2,11 +2,11 @@ public class Main {
public
static
void
main
(
String
[]
args
)
{
Circle
circle1
=
new
Circle
(
19
);
Circle
circle2
=
new
Circle
(
3
);
Rectangle
rect1
=
new
Rectangle
(
1
,
4
,
1
,
4
);
Rectangle
rect2
=
new
Rectangle
(
8
,
5
,
8
,
5
);
Rectangle
rect3
=
new
Rectangle
(
6
,
6
,
6
,
6
);
Triangle
tri1
=
new
Triangle
(
2
,
2
,
2
);
Triangle
tri2
=
new
Triangle
(
4
,
4
,
6
);
Rectangle
rect1
=
new
Rectangle
(
1
,
4
,
1
,
4
);
Rectangle
rect2
=
new
Rectangle
(
8
,
5
,
8
,
5
);
Rectangle
rect3
=
new
Rectangle
(
6
,
6
,
6
,
6
);
Triangle
tri1
=
new
Triangle
(
2
,
2
,
2
);
Triangle
tri2
=
new
Triangle
(
4
,
4
,
6
);
Paint
paint
=
new
Paint
();
paint
.
addCircle
(
circle1
);
paint
.
addCircle
(
circle2
);
...
...
src/Paint.java
View file @
aa1ba37e
import
java.util.ArrayList
;
/**
* paint class
*/
public
class
Paint
{
private
ArrayList
<
Triangle
>
triangles
;
private
ArrayList
<
Rectangle
>
rectangles
;
private
ArrayList
<
Circle
>
circles
;
public
Paint
(){
triangles
=
new
ArrayList
<>();
rectangles
=
new
ArrayList
<>();
circles
=
new
ArrayList
<>();
/**
* paint constructor
*/
public
Paint
()
{
triangles
=
new
ArrayList
<>();
rectangles
=
new
ArrayList
<>();
circles
=
new
ArrayList
<>();
}
public
void
addTriangle
(
Triangle
triangle
){
/**
* @param triangle which is intended to be added
*/
public
void
addTriangle
(
Triangle
triangle
)
{
triangles
.
add
(
triangle
);
}
public
void
addRectangle
(
Rectangle
rectangle
){
/**
* @param rectangle which is intended to be added
*/
public
void
addRectangle
(
Rectangle
rectangle
)
{
rectangles
.
add
(
rectangle
);
}
public
void
addCircle
(
Circle
circle
){
/**
* @param circle which is intended to be added
*/
public
void
addCircle
(
Circle
circle
)
{
circles
.
add
(
circle
);
}
public
void
drawAll
(){
/**
* draws all shapes
*/
public
void
drawAll
()
{
for
(
Triangle
triangle
:
triangles
)
{
triangle
.
draw
();
}
...
...
@@ -30,7 +53,10 @@ public class Paint {
}
}
public
void
printAll
(){
/**
* prints all shapes
*/
public
void
printAll
()
{
for
(
Triangle
triangle
:
triangles
)
{
System
.
out
.
println
(
triangle
.
toString
());
}
...
...
src/Rectangle.java
View file @
aa1ba37e
import
java.util.ArrayList
;
import
java.util.Objects
;
/**
* rectangle class
*/
public
class
Rectangle
{
/**
* sides list for rect
*/
private
ArrayList
<
Integer
>
sides
;
public
Rectangle
(
int
a
,
int
b
,
int
c
,
int
d
){
sides
=
new
ArrayList
<>();
/**
* constructor for rectangle
* @param a side1
* @param b side2
* @param c side3
* @param d side4
*/
public
Rectangle
(
int
a
,
int
b
,
int
c
,
int
d
)
{
sides
=
new
ArrayList
<>();
sides
.
add
(
a
);
sides
.
add
(
b
);
sides
.
add
(
c
);
sides
.
add
(
d
);
}
/**
* @return sides of rect
*/
public
ArrayList
<
Integer
>
getSides
()
{
return
sides
;
}
/**
* @return boolean value of being square
*/
public
boolean
isSquare
()
{
double
a
,
b
,
c
,
d
;
double
a
,
b
,
c
,
d
;
a
=
sides
.
get
(
0
);
b
=
sides
.
get
(
1
);
c
=
sides
.
get
(
2
);
d
=
sides
.
get
(
3
);
return
(
a
==
b
&&
b
==
c
&&
c
==
d
);
return
(
a
==
b
&&
b
==
c
&&
c
==
d
);
}
public
double
calculatePerimeter
(){
return
(
double
)
sides
.
get
(
0
)+
sides
.
get
(
1
)+
sides
.
get
(
2
)+
sides
.
get
(
3
);
/**
* @return perimeter of rect
*/
public
double
calculatePerimeter
()
{
return
(
double
)
sides
.
get
(
0
)
+
sides
.
get
(
1
)
+
sides
.
get
(
2
)
+
sides
.
get
(
3
);
}
public
double
calculateArea
(){
int
a
,
b
,
c
;
a
=
sides
.
get
(
0
);
b
=
sides
.
get
(
1
);
c
=
sides
.
get
(
2
);
if
(
a
==
b
)
return
a
*
c
;
else
if
(
b
==
c
)
return
a
*
b
;
/**
* @return area of rect
*/
public
double
calculateArea
()
{
int
a
,
b
,
c
;
a
=
sides
.
get
(
0
);
b
=
sides
.
get
(
1
);
c
=
sides
.
get
(
2
);
if
(
a
==
b
)
return
a
*
c
;
else
if
(
b
==
c
)
return
a
*
b
;
else
return
b
*
c
;
return
b
*
c
;
}
public
void
draw
(){
System
.
out
.
println
(
"Type: Rectangle\nPerimeter: "
+
calculatePerimeter
()+
"\nArea: "
+
calculateArea
());
/**
* drawing simulation for this shape
*/
public
void
draw
()
{
System
.
out
.
println
(
"Type: Rectangle\nPerimeter: "
+
calculatePerimeter
()
+
"\nArea: "
+
calculateArea
());
}
@Override
...
...
src/Triangle.java
View file @
aa1ba37e
import
java.util.ArrayList
;
import
java.util.Objects
;
/**
* triangle class
*/
public
class
Triangle
{
private
ArrayList
<
Integer
>
sides
;
/**
* constructor for triangle
* @param a first side
* @param b second side
* @param c third side
*/
public
Triangle
(
int
a
,
int
b
,
int
c
){
sides
=
new
ArrayList
<>();
sides
.
add
(
a
);
sides
.
add
(
b
);
sides
.
add
(
c
);
}
/**
* @return sides of triangle
*/
public
ArrayList
<
Integer
>
getSides
()
{
return
sides
;
}
/**
* @return boolean value of being equilateral
*/
public
boolean
isEquilateral
()
{
double
a
,
b
,
c
;
a
=
sides
.
get
(
0
);
...
...
@@ -22,6 +38,9 @@ public class Triangle {
return
(
a
==
b
&&
b
==
c
);
}
/**
* @return perimeter of triangle
*/
public
double
calculatePerimeter
(){
double
a
,
b
,
c
;
a
=
sides
.
get
(
0
);
...
...
@@ -30,6 +49,9 @@ public class Triangle {
return
a
+
b
+
c
;
}
/**
* @return area of triangle
*/
public
double
calculateArea
(){
double
a
,
b
,
c
,
s
;
a
=
sides
.
get
(
0
);
...
...
@@ -39,6 +61,9 @@ public class Triangle {
return
Math
.
sqrt
(
s
*(
s
-
a
)*(
s
-
b
)*(
s
-
c
));
}
/**
* drawing simulation for this shape
*/
public
void
draw
(){
System
.
out
.
println
(
"Type: Triangle\nPerimeter: "
+
calculatePerimeter
()+
"\nArea: "
+
calculateArea
());
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment