Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions oop-basic/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target/
8 changes: 8 additions & 0 deletions oop-basic/src/main/java/com/mitrais/cdc/java/Circle.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
public class Circle {

public double radius;

public Circle(double radius){
this.radius = radius;
}

public double getArea(){
return ((Math.PI)*radius*radius);
}

/*
* todo: make a Circle class with various capabilities below:
Expand Down
24 changes: 21 additions & 3 deletions oop-basic/src/main/java/com/mitrais/cdc/java/CircleOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,60 @@ public void setRandomCircle(){
/*TO DO
* create looping to stored random using Math.random
*/
for(int i=0;i<circles.length;i++){
circles[i] = new Circle(Math.random());
}
}

public Circle[] getRandomCircle(){
setRandomCircle();
return circles;
}

public void setSmallest(Circle[] circles){
/*TO DO
* Create codes to get the smallest area from circles array
*/
smallest = circles[0].getArea();
for (int i = 1; i < circles.length; i++) {
if (circles[i].getArea()<smallest) {
smallest = circles[i].getArea();
}
}
}

public double getSmallest(){

setSmallest(circles);
return smallest;
}

public void setLargest(Circle[] circles){
/*TO DO
* Create codes to get the largest area from circles array
*/
for (int i = 0; i < circles.length; i++) {
if (circles[i].getArea()>largest) {
largest = circles[i].getArea();
}
}
}

public double getLargest(){

setLargest(circles);
return largest;
}

public void setSum(Circle[] circles){
/*TO DO
* Create codes to get the sum area from circles array
*/
for (int i = 0; i < circles.length; i++) {
sum += circles[i].getArea();
}
}

public double getSum(){

setSum(circles);
return sum;
}
}
9 changes: 9 additions & 0 deletions oop-basic/src/main/java/com/mitrais/cdc/java/Rectangle.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
public class Rectangle {

public double width, height;

public Rectangle(double width, double height){
this.width = width;
this.height = height;
}

public double getArea(){
return width * height;
}

/*
* todo: make a Square class with various capabilities below:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,60 @@ public void setRandomRectangle(){
/*TO DO
* create looping to stored random using Math.random
*/
for (int i = 0; i < rectangles.length; i++) {
rectangles[i] = new Rectangle(Math.random(),Math.random());
}
}

public Rectangle[] getRandomRectangle(){
setRandomRectangle();
return rectangles;
}

public void setSmallest(Rectangle[] rectangles){
/*TO DO
* Create codes to get the smallest area from squares array
*/
smallest = rectangles[0].getArea();
for (int i = 1; i < rectangles.length; i++) {
if (rectangles[i].getArea()<smallest) {
smallest = rectangles[i].getArea();
}
}
}

public double getSmallest(){

setSmallest(rectangles);
return smallest;
}

public void setLargest(Rectangle[] rectangles){
/*TO DO
* Create codes to get the largest area from squares array
*/
for (int i = 0; i < rectangles.length; i++) {
if (rectangles[i].getArea()>largest) {
largest = rectangles[i].getArea();
}
}
}

public double getLargest(){

setLargest(rectangles);
return largest;
}

public void setSum(Rectangle[] rectangles){
/*TO DO
* Create codes to get the sum area from squares array
*/
for (int i = 0; i < rectangles.length; i++) {
sum += rectangles[i].getArea();
}
}

public double getSum(){

setSum(rectangles);
return sum;
}

Expand Down
8 changes: 8 additions & 0 deletions oop-basic/src/main/java/com/mitrais/cdc/java/Square.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
public class Square {

public double width;

public Square(double width){
this.width = width;
}

public double getArea(){
return width * width;
}

/*
* todo: make a Square class with various capabilities below:
Expand Down
24 changes: 21 additions & 3 deletions oop-basic/src/main/java/com/mitrais/cdc/java/SquareOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,60 @@ public void setRandomSquare(){
/*TO DO
* create looping to stored random using Math.random
*/
for (int i = 0; i < squares.length; i++) {
squares[i] = new Square(Math.random());
}
}

public Square[] getRandomSquare(){
setRandomSquare();
return squares;
}

public void setSmallest(Square[] squares){
/*TO DO
* Create codes to get the smallest area from squares array
*/
smallest = squares[0].getArea();
for (int i = 1; i < squares.length; i++) {
if (squares[i].getArea()<smallest) {
smallest = squares[i].getArea();
}
}
}

public double getSmallest(){

setSmallest(squares);
return smallest;
}

public void setLargest(Square[] squares){
/*TO DO
* Create codes to get the largest area from squares array
*/
for (int i= 0; i< squares.length; i++) {
if (squares[i].getArea()>largest) {
largest = squares[i].getArea();
}
}
}

public double getLargest(){

setLargest(squares);
return largest;
}

public void setSum(Square[] squares){
/*TO DO
* Create codes to get the sum area from squares array
*/
for (int i = 0; i < squares.length; i++) {
sum += squares[i].getArea();
}
}

public double getSum(){

setSum(squares);
return sum;
}
}