Добавил:
Eatmore
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:отчеты по лабораторным работам / лабораторная работа 1 / java.lab1 / PointInArea
.java class PointInArea extends Point
implements IfaceArea {
private enum Quarters { first , second, third, fourth };
private Quarters qrtr;
public PointInArea (double x_coord) {
this (x_coord, x_coord);
}
public PointInArea (double x_coord, double y_coord) {
super (x_coord, y_coord);
if (x_coord >= 0)
if (y_coord >= 0)
qrtr = Quarters.first;
else qrtr = Quarters.fourth;
else if (y_coord >= 0)
qrtr = Quarters.second;
else qrtr = Quarters.third;
}
public boolean isInArea (double R) {
switch (qrtr) {
case second:
if (x >= -R/2 && y <= R)
return true;
break;
case third:
if (y >= (-x - R))
return true;
break;
case fourth:
if ((Math.pow(x, 2) + Math.pow(y, 2)) <= Math.pow(R, 2))
return true;
break;
}
return false;
}
}
implements IfaceArea {
private enum Quarters { first , second, third, fourth };
private Quarters qrtr;
public PointInArea (double x_coord) {
this (x_coord, x_coord);
}
public PointInArea (double x_coord, double y_coord) {
super (x_coord, y_coord);
if (x_coord >= 0)
if (y_coord >= 0)
qrtr = Quarters.first;
else qrtr = Quarters.fourth;
else if (y_coord >= 0)
qrtr = Quarters.second;
else qrtr = Quarters.third;
}
public boolean isInArea (double R) {
switch (qrtr) {
case second:
if (x >= -R/2 && y <= R)
return true;
break;
case third:
if (y >= (-x - R))
return true;
break;
case fourth:
if ((Math.pow(x, 2) + Math.pow(y, 2)) <= Math.pow(R, 2))
return true;
break;
}
return false;
}
}