Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Program
- {
- static void Main()
- {
- try
- {
- double length = double.Parse(Console.ReadLine());
- double width = double.Parse(Console.ReadLine());
- double height = double.Parse(Console.ReadLine());
- Box box = new Box(length, width, height);
- Console.WriteLine($"Surface Area - {box.BoxSurfaceArea(box):f2}" +
- $"{Environment.NewLine}Lateral Surface Area - {box.BoxLateralSurface(box):f2}" +
- $"{Environment.NewLine}Volume - {box.BoxVolume(box):f2}");
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- }
- }
- public class Box
- {
- private double _length;
- private double _width;
- private double _height;
- private double Length
- {
- get => _length;
- set
- {
- if (value <= 0)
- {
- throw new ArgumentException($"{nameof(Length)} cannot be zero or negative.");
- }
- this._length = value;
- }
- }
- private double Width
- {
- get => _width;
- set
- {
- if (value <= 0)
- {
- throw new ArgumentException($"{nameof(Width)} cannot be zero or negative.");
- }
- this._width = value;
- }
- }
- private double Height
- {
- get => _height;
- set
- {
- if (value <= 0)
- {
- throw new ArgumentException($"{nameof(Height)} cannot be zero or negative.");
- }
- this._height = value;
- }
- }
- //Volume = lwh
- //Lateral Surface Area = 2lh + 2wh
- //Surface Area = 2lw + 2lh + 2wh
- public Box(double length, double width, double height)
- {
- Length = length;
- Width = width;
- Height = height;
- }
- public double BoxVolume(Box box)
- {
- return box.Length * box.Width * box.Height;
- }
- public double BoxLateralSurface(Box box)
- {
- return 2 * (box.Length * box.Height) + 2 * (box.Width * box.Height);
- }
- public double BoxSurfaceArea(Box box)
- {
- return 2 * (box.Length * box.Height) + 2 * (box.Width * box.Height) + 2 * (box.Length * box.Width);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment