把test.java救回来了

This commit is contained in:
2024-06-11 01:53:01 +08:00
parent d085000064
commit d753356d40
54 changed files with 1309 additions and 1297 deletions
+15 -15
View File
@@ -1,15 +1,15 @@
//Cuboid.java
package task4;
public class Cuboid extends Rectangle {
double height;
public Cuboid(double length, double width, double height) {
super(length, width);
this.height = height;
}
public double volume() {
return this.length * this.width * this.height;
}
}
//Cuboid.java
package task4;
public class Cuboid extends Rectangle {
double height;
public Cuboid(double length, double width, double height) {
super(length, width);
this.height = height;
}
public double volume() {
return this.length * this.width * this.height;
}
}
+24 -24
View File
@@ -1,24 +1,24 @@
//Rectangle.java
package task4;
public class Rectangle {
double length;
double width;
public double getPerimeter() {
return (this.length + this.width) * 2;
}
public double getArea() {
return this.length * this.width;
}
public Rectangle(double length, double width) {
this.length = length;
this.width = width;
}
public Rectangle() {
this(1.0, 1.0);
}
}
//Rectangle.java
package task4;
public class Rectangle {
double length;
double width;
public double getPerimeter() {
return (this.length + this.width) * 2;
}
public double getArea() {
return this.length * this.width;
}
public Rectangle(double length, double width) {
this.length = length;
this.width = width;
}
public Rectangle() {
this(1.0, 1.0);
}
}
+20 -20
View File
@@ -1,20 +1,20 @@
//Test.java
package task4;
public class Test {
public static void main(String[] args) {
Rectangle r1 = new Rectangle(3, 4);
System.out.println("r1's perimeter:\t" + r1.getPerimeter());
System.out.println("r1's area:\t" + r1.getArea());
System.out.println("__________________________________");
Rectangle r2 = new Rectangle();
System.out.println("r2's perimeter:\t" + r2.getPerimeter());
System.out.println("r2's area:\t" + r2.getArea());
System.out.println("__________________________________");
Cuboid c = new Cuboid(3, 4, 5);
System.out.println("bottom of c's perimeter:\t" + c.getPerimeter());
System.out.println("bottom c's area:\t" + c.getArea());
System.out.println("c's volume:\t" + c.volume());
}
}
//Test.java
package task4;
public class Test {
public static void main(String[] args) {
Rectangle r1 = new Rectangle(3, 4);
System.out.println("r1's perimeter:\t" + r1.getPerimeter());
System.out.println("r1's area:\t" + r1.getArea());
System.out.println("__________________________________");
Rectangle r2 = new Rectangle();
System.out.println("r2's perimeter:\t" + r2.getPerimeter());
System.out.println("r2's area:\t" + r2.getArea());
System.out.println("__________________________________");
Cuboid c = new Cuboid(3, 4, 5);
System.out.println("bottom of c's perimeter:\t" + c.getPerimeter());
System.out.println("bottom c's area:\t" + c.getArea());
System.out.println("c's volume:\t" + c.volume());
}
}