SenpaiZero

TriPrism

Jun 5th, 2024
988
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.86 KB | None | 0 0
  1. public class TriPrism<T extends Number> {
  2.     // Private variables for the dimensions of the prism
  3.     private T length;
  4.     private T base;
  5.     private T height;
  6.  
  7.     // Getters and setters for length
  8.     public T getLength() {
  9.         return length;
  10.     }
  11.  
  12.     public void setLength(T length) {
  13.         this.length = length;
  14.     }
  15.  
  16.     // Getters and setters for base
  17.     public T getBase() {
  18.         return base;
  19.     }
  20.  
  21.     public void setBase(T base) {
  22.         this.base = base;
  23.     }
  24.  
  25.     // Getters and setters for height
  26.     public T getHeight() {
  27.         return height;
  28.     }
  29.  
  30.     public void setHeight(T height) {
  31.         this.height = height;
  32.     }
  33.  
  34.     // Calculate the volume of the triangular prism
  35.     public double calculateVolume() {
  36.         return length.doubleValue() * 0.5 * base.doubleValue() * height.doubleValue();
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment