Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ClassBoxData
- {
- public class StartUp
- {
- static void Main(string[] args)
- {
- 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.SurfaceArea():f2}");
- Console.WriteLine($"Lateral Surface Area - {box.LateralSurfaceArea():f2}");
- Console.WriteLine($"Volume - {box.Volume():f2}");
- }
- catch(ArgumentException ex)
- {
- Console.WriteLine(ex.Message);
- }
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace ClassBoxData
- {
- 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 => this.length;
- private set
- {
- this.ThrowIfIsRangeNumbers(value, nameof(this.Length));
- this.length = value;
- }
- }
- public double Width
- {
- get => this.width;
- private set
- {
- this.ThrowIfIsRangeNumbers(value, nameof(this.Width));
- this.width = value;
- }
- }
- public double Height
- {
- get => this.height;
- private set
- {
- this.ThrowIfIsRangeNumbers(value, nameof(this.Height));
- this.height = value;
- }
- }
- public double Volume()
- {
- double res = this.Length * this.Width * this.Height;
- return res;
- }
- public double SurfaceArea()
- {
- return 2 * this.Length * this.Width + 2 * this.Length * this.Height + 2 * this.Width * this.Height;
- }
- public double LateralSurfaceArea()
- {
- return 2 * this.Length * this.Height + 2 * this.Width * this.Height;
- }
- private void ThrowIfIsRangeNumbers(double value, string side)
- {
- if (value <= 0)
- {
- throw new ArgumentException($"{side} cannot be zero or negative.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement