Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
AsifShawon authored Sep 9, 2023
1 parent 7914a60 commit f31580d
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 0 deletions.
70 changes: 70 additions & 0 deletions MorePractice/Class_basic/Box.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package class_basic;

public class Box {
private double width, height, depth;

public Box(){
width = 5;
height = 10;
depth = 2;
}
public Box(double len){
width = height = depth = len;
}

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

public Box(Box box){
width = box.width;
depth = box.depth;
height = box.height;
}


public double getWidth() {
return width;
}

public void setWidth(double width) {
this.width = width;
}

public double getHeight() {
return height;
}

public void setHeight(double height) {
this.height = height;
}

public double getDepth() {
return depth;
}

public void setDepth(double depth) {
this.depth = depth;
}

public void setDim(double width, double height, double depth){
this.width = width;
this.height = height;
this.depth = depth;
}

public boolean equalTo(Box o){
return (o.width==width && o.height==height && o.depth==depth);
}

public double volume(){
return height*width*depth;
}

@Override
public String toString() {
return "Box[width=" + width + ",height=" + height + ",depth=" + depth + "]";
}
}
15 changes: 15 additions & 0 deletions MorePractice/Class_basic/Rectangle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package class_basic;

public class Rectangle {
private int width, length;

// constructor - special method, named as "ClassName" and no return type
public Rectangle(int width, int length){
this.width = width;
this.length = length;
}

public double getArea(){
return width*length;
}
}
11 changes: 11 additions & 0 deletions MorePractice/Class_basic/box_test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package class_basic;

public class box_test {
public static void main(String[] args) {
Box box1 = new Box();
// Test constructors and toString()
System.out.println(box1.toString()); // Explicitly calling toString()
System.out.println(box1); // Implicit call to
System.out.println(box1.volume());
}
}
12 changes: 12 additions & 0 deletions MorePractice/Class_basic/test_rectangle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package class_basic;

public class test_rectangle {
public static void main(String[] args) {
Rectangle rectangle_1 = new Rectangle(5, 10);
Rectangle rectangle_2 = new Rectangle(6, 12);

System.out.println("Area of the rectangle = " + rectangle_1.getArea());
System.out.println("Area of the rectangle 2 = " + rectangle_2.getArea());
}

}

0 comments on commit f31580d

Please sign in to comment.