Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ClassBox
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- 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;
- }
- set
- {
- ThrowExceptionIfSideIsNegative(value, nameof(this.Length));
- this.length = value;
- }
- }
- public double Width
- {
- get
- {
- return this.width;
- }
- set
- {
- ThrowExceptionIfSideIsNegative(value, nameof(this.Width));
- this.width = value;
- }
- }
- public double Height
- {
- get
- {
- return this.height;
- }
- set
- {
- ThrowExceptionIfSideIsNegative(value, nameof(this.Height));
- this.height = value;
- }
- }
- private void ThrowExceptionIfSideIsNegative(double side, string sideName)
- {
- if (side <= 0)
- {
- Console.WriteLine($"{sideName} cannot be zero or negative.");
- Environment.Exit(0);
- }
- }
- private double Multiply(double first, double second)
- {
- return (first * second) * 2;
- }
- public double LateralSurfaceArea()
- {
- return Multiply(length, height) + Multiply(width, height);
- }
- public double SurfaceArea()
- {
- return Multiply(length, width) + Multiply(length, height) + Multiply(width, height);
- }
- public double Volume()
- {
- return length * width * height;
- }
- }
- }
Add Comment
Please, Sign In to add comment