Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- public class Box
- {
- private double length;
- private double width;
- private double height;
- public Box(double length, double width, double height)
- {
- this.Length = length;
- this.Width = width;
- this.Height = height;
- }
- public double Length
- {
- get { return this.length; }
- private set
- {
- if (!ValidateInput(value))
- {
- throw new ArgumentException("Length cannot be zero or negative.");
- }
- this.length = value;
- }
- }
- public double Width
- {
- get { return this.width; }
- private set
- {
- if (!ValidateInput(value))
- {
- throw new ArgumentException("Width cannot be zero or negative.");
- }
- this.width = value;
- }
- }
- public double Height
- {
- get { return this.height; }
- private set
- {
- if (!ValidateInput(value))
- {
- throw new ArgumentException("Height cannot be zero or negative.");
- }
- this.height = value;
- }
- }
- public double SurfaceArea()
- {
- return 2 * length * width + 2 * length * height + 2 * width * height;
- }
- public double LateralSurfaceArea()
- {
- return 2 * length * height + 2 * width * height;
- }
- public double Volume()
- {
- return length * width * height;
- }
- private bool ValidateInput(double value)
- {
- return value > 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment