Advertisement
abasar

Box

Sep 4th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.19 KB | None | 0 0
  1. //main
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6.  
  7. namespace ConsoleApplication1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Box[] arr = new Box[5];
  14.             for (int i = 0; i < arr.Length; i++) {
  15.                 Console.Write("Enter Length: ");
  16.                 double length = double.Parse(Console.ReadLine());
  17.                 Console.Write("Enter Width: ");
  18.                 double width = double.Parse(Console.ReadLine());
  19.                 Console.Write("Enter Height: ");
  20.                 double height = double.Parse(Console.ReadLine());
  21.                
  22.                 arr[i] = new Box(length, width, height);
  23.             }
  24.             for (int i = 0; i < arr.Length; i++)
  25.                 Console.WriteLine(arr[i].ToString());
  26.         }
  27.     }
  28. }
  29.  
  30. //Box.cs
  31. using System;
  32. using System.Collections.Generic;
  33. using System.Linq;
  34. using System.Text;
  35.  
  36. namespace ConsoleApplication1
  37. {
  38.     class Box
  39.     {
  40.         private double length;
  41.         private double width;
  42.         private double height;
  43.  
  44.         public Box(double length, double width, double height)
  45.         {
  46.             this.length = length;
  47.             this.width = width;
  48.             this.height = height;
  49.         }
  50.  
  51.         public double GetLength()
  52.         {
  53.             return this.length;
  54.         }
  55.  
  56.         public double GetWidth()
  57.         {
  58.             return this.width;
  59.         }
  60.  
  61.         public double GetHeight()
  62.         {
  63.             return this.height;
  64.         }
  65.  
  66.         public void SetLength(double length)
  67.         {
  68.             this.length = length;
  69.         }
  70.  
  71.         public void SetWidth(double width)
  72.         {
  73.             this.width = width;
  74.         }
  75.  
  76.         public void SetHeight(double height)
  77.         {
  78.             this.height = height;
  79.         }
  80.  
  81.         public double GetVolume()
  82.         {
  83.             return this.height * this.width * this.length;
  84.         }
  85.  
  86.         public string ToString()
  87.         {
  88.             return "The box's length is " + this.length + ", width is " + this.width + ", height is " + this.height + ", volume is " + this.GetVolume();
  89.         }
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement