Advertisement
mmayoub

Ex01P026-Line.cs

Nov 18th, 2021
739
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.98 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace ConsoleApp7
  6. {
  7.     // Ex01 - P026
  8.     class Line
  9.     {
  10.         private double x1, y1;
  11.         private double x2, y2;
  12.         private String color;
  13.         private double width;
  14.  
  15.         public Line(double x1, double y1, double x2, double y2)
  16.         {
  17.             this.x1 = x1;
  18.             this.y1 = y1;
  19.             this.x2 = x2;
  20.             this.y2 = y2;
  21.             this.color = "Black";
  22.             this.width = 1;
  23.         }
  24.  
  25.         public Line(double x1, double y1, double x2, double y2, String color, double width)
  26.         {
  27.             this.x1 = x1;
  28.             this.y1 = y1;
  29.             this.x2 = x2;
  30.             this.y2 = y2;
  31.             this.color = color;
  32.             this.width = width;
  33.         }
  34.  
  35.         // setters
  36.         public void setX1(double x1) { this.x1 = x1; }
  37.         public void setY1(double y1) { this.y1 = y1; }
  38.         public void setX2(double x2) { this.x2 = x2; }
  39.         public void setY2(double y2) { this.y2 = y2; }
  40.         public void setColor(String color) { this.color = color; }
  41.         public void setWidth(double width) { this.width = width; }
  42.  
  43.         // getters
  44.         public double getX1(double x1) { return x1; }
  45.         public double getY1(double y1) { return y1; }
  46.         public double getX2(double x2) { return x2; }
  47.         public double getY2(double y2) { return y2; }
  48.         public string getColor(String color) { return color; }
  49.         public double getWidth(double width) { return width; }
  50.  
  51.         // ToString
  52.         public override string ToString()
  53.         {
  54.             return String.Format("Line from ({0}, {1}) to ({2}, {3}), color={4} and width={5}", x1, y1, x2, y2, color, width);
  55.         }
  56.  
  57.         public double getLength()
  58.         {
  59.             double dx2 = Math.Pow(x2 - x1, 2);
  60.             double dy2 = Math.Pow(y2 - y1, 2);
  61.  
  62.             double l = Math.Sqrt(dx2 + dy2);
  63.  
  64.             return l;
  65.         }
  66.     }
  67. }
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement