Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
6-8 calculated surface area and volume of a rectangular parallelepiped (10 minutes)
Please complete the relevant code to achieve the surface area and volume of a rectangular parallelepiped is calculated
Function interface definition:
See detailed invocation of the main program.
Referee test program Example:
import java.util.Scanner;
/* 你的代码将被嵌入到这里 */
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double l = input.nextDouble();
double w = input.nextDouble();
double h = input.nextDouble();
Cuboid myCuboid = new Cuboid(l, w, h);
System.out.printf("%.4f",myCuboid.getArea());
System.out.println();
System.out.printf("%.4f",myCuboid.getVolume());
input.close();
}
}
Sample input:
Here we are given a set of inputs. E.g:
3.5 2 5
Sample output:
Given here corresponding output. E.g:
69.0000
35.0000
answer
class Cuboid {
private double l;
private double w;
private double h;
Cuboid(double l, double w, double h) {
this.l = l;
this.w = w;
this.h = h;
}
public double getArea() {
return 2 * ((l * w) + (l * h) + (h * w));
}
public double getVolume() {
return l * w * h;
}
}