Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace ConsoleApp7
- {
- // Ex01 - P026
- class Line
- {
- private double x1, y1;
- private double x2, y2;
- private String color;
- private double width;
- public Line(double x1, double y1, double x2, double y2)
- {
- this.x1 = x1;
- this.y1 = y1;
- this.x2 = x2;
- this.y2 = y2;
- this.color = "Black";
- this.width = 1;
- }
- public Line(double x1, double y1, double x2, double y2, String color, double width)
- {
- this.x1 = x1;
- this.y1 = y1;
- this.x2 = x2;
- this.y2 = y2;
- this.color = color;
- this.width = width;
- }
- // setters
- public void setX1(double x1) { this.x1 = x1; }
- public void setY1(double y1) { this.y1 = y1; }
- public void setX2(double x2) { this.x2 = x2; }
- public void setY2(double y2) { this.y2 = y2; }
- public void setColor(String color) { this.color = color; }
- public void setWidth(double width) { this.width = width; }
- // getters
- public double getX1(double x1) { return x1; }
- public double getY1(double y1) { return y1; }
- public double getX2(double x2) { return x2; }
- public double getY2(double y2) { return y2; }
- public string getColor(String color) { return color; }
- public double getWidth(double width) { return width; }
- // ToString
- public override string ToString()
- {
- return String.Format("Line from ({0}, {1}) to ({2}, {3}), color={4} and width={5}", x1, y1, x2, y2, color, width);
- }
- public double getLength()
- {
- double dx2 = Math.Pow(x2 - x1, 2);
- double dy2 = Math.Pow(y2 - y1, 2);
- double l = Math.Sqrt(dx2 + dy2);
- return l;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement