package Exercises; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class line { // закрытые поля класса private int x1; private int y1; private int x2; private int y2; // метод записи значения В поле класса (сеттер - setter) public void set_x1(int x1) throws IOException { if (x1 < 0) { do { System.out.println("Введите неотрицательное значение координаты: "); BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); try { x1 = Integer.parseInt(r.readLine()); } catch (NumberFormatException e) { System.out.println("Wrong format number"); } } while (x1<0); } this.x1 = x1; } public void set_y1(int y1) { this.y1 = y1; } public void set_x2(int x2) { this.x2 = x2; } public void set_y2(int y2) { this.y2 = y2; } // метод считывания значения ИЗ поля класса (геттер - getter ) public int get_x1() { return this.x1; } public int get_y1() { return this.y1; } public int get_x2() { return this.x2; } public int get_y2() { return this.y2; } // конструктор без параметров line () { this.x1 = 0; this.y1 = 0; this.x2 = 0; this.y2 = 0; } // конструктор с 4 параметрами line (int x1, int y1, int x2, int y2) { this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2; } // метод вывода на экран информации об объекте void print() { System.out.println("("+this.x1+", " + this.y1 + ") - (" + this.x2 + ", " + this.y2 + ")\n"); } // метод вычисления длины отрезка float length() { return (float) Math.sqrt(Math.pow((float)(this.x2-this.x1), 2.0)+Math.pow((float)(this.y2-this.y1), 2.0)); } }