- Added javadoc for all classes
	- update gitignore
This commit is contained in:
HeshamTB 2020-09-05 22:48:38 +03:00
parent 8e8c36d091
commit f64343c59c
Signed by: Hesham
GPG Key ID: 74876157D199B09E
6 changed files with 137 additions and 6 deletions

4
.gitignore vendored
View File

@ -1,2 +1,6 @@
*.class *.class
*.zip *.zip
*.xz
#build output
out/

View File

@ -0,0 +1,8 @@
<component name="ArtifactManager">
<artifact type="jar" name="lab-01:jar">
<output-path>$PROJECT_DIR$/out/artifacts/lab_01_jar</output-path>
<root id="archive" name="lab-01.jar">
<element id="module-output" name="lab-01" />
</root>
</artifact>
</component>

View File

@ -2,27 +2,53 @@ public class Circle extends _Point {
private double radius; private double radius;
/**
* construct a circle of radius r at origin
* @param radius
*/
public Circle(double radius){ public Circle(double radius){
this.radius = radius; this.radius = radius;
this.setLocation(0, 0); this.setLocation(0, 0);
} }
/**
* construct a circle of radius r at (x,y)
* @param radius
* @param x
* @param y
*/
public Circle(double radius, int x, int y){ public Circle(double radius, int x, int y){
this.radius = radius; this.radius = radius;
this.setLocation(x, y); this.setLocation(x, y);
} }
/**
* set radius
* @param radius
*/
public void setRadius(double radius) { this.radius = radius; } public void setRadius(double radius) { this.radius = radius; }
/**
* get radius
* @return radius
*/
public double getRadius(){ return this.radius; } public double getRadius(){ return this.radius; }
/**
* get area
* @return area
*/
public double getArea() { return (Math.PI*Math.pow(radius, 2)); } public double getArea() { return (Math.PI*Math.pow(radius, 2)); }
public double getCircumfrence() { return 2*Math.PI*this.radius; } /**
* get circumference
* @return circumference
*/
public double getCircumference() { return 2*Math.PI*this.radius; }
public String toString() { public String toString() {
String format = "%sCircle's radius = %.2f ,area = %.2f, circumfrence = %.2f\n"; String format = "%sCircle's radius = %.2f ,area = %.2f, circumference = %.2f\n";
return String.format(format, super.toString(), getRadius(), getArea(), getCircumfrence()); return String.format(format, super.toString(), getRadius(), getArea(), getCircumference());
} }
} }

View File

@ -2,6 +2,11 @@ public class Cylinder extends Circle {
private double height; private double height;
/**
* Construct a cylinder at origin with Radius r and height h
* @param r radius
* @param h height
*/
public Cylinder(double r, double h){ public Cylinder(double r, double h){
super(r);//Recommended by IDE. Invokes Circle(double radius). super(r);//Recommended by IDE. Invokes Circle(double radius).
// Circle with location 0, 0 and radius r. // Circle with location 0, 0 and radius r.
@ -9,22 +14,45 @@ public class Cylinder extends Circle {
//now a cylinder with radius r and height h at 0,0 //now a cylinder with radius r and height h at 0,0
} }
/**
* Construct a cylinder at (x,y) with Radius r and height h
* @param x X
* @param y Y
* @param r radius
* @param h height
*/
public Cylinder(int x, int y,double r, double h){ public Cylinder(int x, int y,double r, double h){
super(r, x, y); //a circle with radius r at x,y super(r, x, y); //a circle with radius r at x,y
this.height = h; this.height = h;
//cylinder with radius r and height h at x,y //cylinder with radius r and height h at x,y
} }
/**
* get surface area of cylinder
* @return surface area
*/
public double getSurfaceArea(){ public double getSurfaceArea(){
return 2*(Math.PI*getRadius()*getHeight() + Math.PI*Math.pow(getRadius(),2)); return 2*(Math.PI*getRadius()*getHeight() + Math.PI*Math.pow(getRadius(),2));
} }
/**
* get volume of cylinder
* @return volume
*/
public double getVolume(){ public double getVolume(){
return Math.PI*Math.pow(getRadius(), 2)*getHeight(); return Math.PI*Math.pow(getRadius(), 2)*getHeight();
} }
/**
* set height h
* @param h
*/
public void setHeight(double h){ this.height = h;} public void setHeight(double h){ this.height = h;}
/**
* get height
* @return height
*/
public double getHeight(){ return this.height; } public double getHeight(){ return this.height; }
public String toString(){ public String toString(){

View File

@ -3,6 +3,11 @@ public class _Point {
private int x; private int x;
private int y; private int y;
/**
* Construct a point with cartesian coordinates
* @param x
* @param y
*/
public _Point(int x, int y){ public _Point(int x, int y){
this.x = x; this.x = x;
@ -10,6 +15,9 @@ public class _Point {
} }
/**
* Construct origin point
*/
public _Point(){ public _Point(){
this.x = 0; this.x = 0;
@ -17,6 +25,11 @@ public class _Point {
} }
/**
* Set location of point
* @param x
* @param y
*/
public void setLocation(int x, int y){ public void setLocation(int x, int y){
this.x = x; this.x = x;
@ -24,12 +37,28 @@ public class _Point {
} }
/**
* Get current X
* @return X
*/
public int getX(){ return x; } public int getX(){ return x; }
/**
* Get current Y
* @return Y
*/
public int getY(){ return y; } public int getY(){ return y; }
/**
* set X
* @param x
*/
public void setX(int x){ this.x = x; } public void setX(int x){ this.x = x; }
/**
* set Y
* @param y
*/
public void setY(int y){ this.y = y; } public void setY(int y){ this.y = y; }
public String toString(){ return String.format("Current (x,y) location (%d,%d)\n", this.x, this.y); } public String toString(){ return String.format("Current (x,y) location (%d,%d)\n", this.x, this.y); }

View File

@ -3,32 +3,68 @@ public class _Rectangle extends _Point {
private double height; private double height;
private double width; private double width;
/**
* Construct Rectangle with location (0,0)
* @param width width of rectangle
* @param height height of rectangle
*/
public _Rectangle(double width, double height){ public _Rectangle(double width, double height){
this.height = height; this.height = height;
this.width = width; this.width = width;
this.setLocation(0, 0); this.setLocation(0, 0);
} }
/**
* Construct a rectangle
* @param x x coordinate
* @param y y coordinate
* @param w width of rectangle
* @param h height of rectangle
*/
public _Rectangle(int x, int y, double w, double h){ public _Rectangle(int x, int y, double w, double h){
this.width = w; this.width = w;
this.height = h; this.height = h;
this.setLocation(x, y); this.setLocation(x, y);
} }
/**
* set height of rectangle
* @param h height
*/
public void setHeight(double h){ this.height = h; } public void setHeight(double h){ this.height = h; }
/**
* set width of rectangle
* @param w width
*/
public void setWidth(double w){ this.width = w; } public void setWidth(double w){ this.width = w; }
/**
* returns height
* @return height
*/
public double getHeight(){ return this.height; } public double getHeight(){ return this.height; }
/**
* returns width
* @return width
*/
public double getWidth(){ return this.width; } public double getWidth(){ return this.width; }
/**
* returns area
* @return area
*/
public double getArea(){ return this.height*this.width; } public double getArea(){ return this.height*this.width; }
public double getCircumfrence(){ return 2*(this.width+this.height); } /**
* returns circumference
* @return circumference
*/
public double getCircumference(){ return 2*(this.width+this.height); }
public String toString() { public String toString() {
return String.format("%sRectangle's Height %.2f, Width %.2f, Area %.2f, Circumfrence %.2f", return String.format("%sRectangle's Height %.2f, Width %.2f, Area %.2f, Circumference %.2f",
super.toString(), getHeight(), getWidth(), getArea(), getCircumfrence()); super.toString(), getHeight(), getWidth(), getArea(), getCircumference());
} }
} }