Geometric cube

Report a typo

You have a class GeometricCuboid with a 3-argument constructor:

public GeometricCuboid(int width, int height, int length)

Write a program that reads width, height and length, creates an instance named cuboid and outputs the result of cuboid.toString().

Use the provided template, do not change it!

Write a program in Java 17
import java.util.Scanner;

public class Main {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

int width = scanner.nextInt();
int height = scanner.nextInt();
int length = scanner.nextInt();

// creating an instance

System.out.println(cuboid.toString());
}
}

class GeometricCuboid {
private int width;
private int height;
private int length;

public GeometricCuboid(int width, int height, int length) {
this.width = width;
this.height = height;
this.length = length;
}

@Override
public String toString() {
return "Cuboid(" +
"w=" + width +
", h=" + height +
", l=" + length + ')';
}
___

Create a free account to access the full topic