Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- public class StartUp
- {
- public static void Main()
- {
- double length = double.Parse(Console.ReadLine());
- double width = double.Parse(Console.ReadLine());
- double height = double.Parse(Console.ReadLine());
- var box = new Box(length, width, height);
- try
- {
- double surfaceArea = box.SurfaceArea();
- double lateralSurfaceArea = box.LateralSurfaceArea();
- double volume = box.Volume();
- Console.WriteLine($"Surface Area - {surfaceArea:f2}");
- Console.WriteLine($"Lateral Surface Area - {lateralSurfaceArea:f2}");
- Console.WriteLine($"Volume - {volume:f2}");
- }
- catch (ArgumentException argEx)
- {
- Console.WriteLine(argEx.Message);
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Text;
- public class Box
- {
- private double length;
- public double Length
- {
- set
- {
- if (value <= 0)
- {
- throw new ArgumentException("Length cannot be zero or negative.");
- }
- this.length = value;
- }
- }
- private double width;
- public double Width
- {
- set
- {
- if (value <= 0)
- {
- throw new ArgumentException("Width cannot be zero or negative.");
- }
- this.width = value;
- }
- }
- private double height;
- public double Height
- {
- set
- {
- if (value <= 0)
- {
- throw new ArgumentException("Height cannot be zero or negative.");
- }
- this.height = value;
- }
- }
- public Box(double length, double width, double height)
- {
- this.Length = length;
- this.Width = width;
- this.Height = height;
- }
- public double SurfaceArea()
- {
- double surfaceArea = 2 * length * width + 2 * length * height + 2 * width * height;
- return surfaceArea;
- }
- public double LateralSurfaceArea()
- {
- double lateralSurfaceArea = 2 * length * height + 2 * width * height;
- return lateralSurfaceArea;
- }
- public double Volume()
- {
- double volume = length * width * height;
- return volume;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment