Завершено третье задание ЛР2

This commit is contained in:
Victor 2013-10-04 17:53:22 +03:00
parent 857973a51e
commit 6e2ab63405
6 changed files with 81 additions and 7 deletions

View File

@ -2,6 +2,7 @@ package tse;
import tse.lr2.CompareArrays1D;
import tse.lr2.CompareArrays2D;
import tse.lr2.LR_2_Tasks;
/**
* @author aNNiMON
@ -11,7 +12,7 @@ public class LR_2 implements ILabRab {
private static final String[] TITLES = {
"Копирование и сравнение массивов",
"Двумерный массив строк",
"3",
"Эллипсы и круги. Массив",
"4",
"5"
};
@ -26,7 +27,7 @@ public class LR_2 implements ILabRab {
CompareArrays2D.main();
break;
case 2:
LR_2_Tasks.getInstance().task3();
break;
case 3:

View File

@ -8,6 +8,14 @@ import java.awt.Point;
*/
public class Circle extends Ellipse {
public Circle() {
super();
}
public Circle(Point p1, Point p2, Point p3, Point p4) {
super(p1, p2, p3, p4);
}
public boolean isConsist(Point point) {
Point center = getCenterPoint();
int radius = center.x - points[0].x;
@ -20,7 +28,7 @@ public class Circle extends Ellipse {
@Override
public String toString() {
return "This is circle!\n" + super.toString();
return "Круг - твой друг!";
}
}

View File

@ -15,7 +15,7 @@ public class CompareArrays1D {
String[] b3 = Arrays.copyOf(a, a.length);
String[] b4 = {"1","2","3"};
System.out.print("b\t\t\tb==a\tb.equals(a)\tArrays.equals(a,b) deepEquals\t\tb[0]==a[0]");
System.out.print("\nb\t\t\tb==a\tb.equals(a)\tArrays.equals(a,b) deepEquals\t\tb[0]==a[0]");
printRow("b=a\t\t\t", getValues(a, b1));
printRow("b=a.clone()\t\t", getValues(a, b2));
printRow("b=Arrays.copyOf(a)\t", getValues(a, b3));

View File

@ -15,7 +15,7 @@ public class CompareArrays2D {
String[][] b3 = Arrays.copyOf(a, a.length);
String[][] b4 = { {"1","2","3"}, {"4", "5", "6"}, {"7", "8", "9"} };
System.out.print("b\t\t\tb==a\tb.equals(a)\tArrays.equals(a,b) deepEquals\t\tb[0]==a[0]");
System.out.print("\nb\t\t\tb==a\tb.equals(a)\tArrays.equals(a,b) deepEquals\t\tb[0]==a[0]");
printRow("b=a\t\t\t", getValues(a, b1));
printRow("b=a.clone()\t\t", getValues(a, b2));
printRow("b=Arrays.copyOf(a)\t", getValues(a, b3));

View File

@ -78,13 +78,14 @@ public class Ellipse {
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
/*StringBuilder sb = new StringBuilder();
for (int i = 0; i < POINTS; i++) {
sb.append(points[i].toString()).append('\t');
}
sb.append("\nSquare: ").append(getSquare());
sb.append("\nCenter: ").append(getCenterPoint().toString());
return sb.toString();
return sb.toString();*/
return "Я - Эллипс";
}
}

View File

@ -0,0 +1,64 @@
package tse.lr2;
import java.awt.Point;
/**
*
* @author aNNiMON
*/
public class LR_2_Tasks {
private static LR_2_Tasks instance;
public static synchronized LR_2_Tasks getInstance() {
if (instance == null) instance = new LR_2_Tasks();
return instance;
}
private Ellipse ellipse1, ellipse2, ellipse3;
private Circle circle1, circle2;
private Point point1;
public void task3() {
makeObjects();
Ellipse[] arr1 = new Ellipse[] {
ellipse1, ellipse2, ellipse3, circle1, circle2
};
for (Ellipse item : arr1) {
System.out.println("----------");
System.out.println("Класс: " + item.getClass().getName());
System.out.println("Центр: " + item.getCenterPoint().toString());
System.out.println("Площадь: " + item.getSquare());
System.out.println("Расстояние от другого эллипса: " + item.getDistanceOfCentres(ellipse2));
if (item instanceof Circle) {
boolean consist = ((Circle)item).isConsist(point1);
System.out.println("Круг. Находится ли точка внутри? " + (consist ? "Да" : "Нет"));
}
System.out.println(item.toString());
}
}
private void makeObjects() {
ellipse1 = new Ellipse(
new Point(2, 2), new Point(8, 2),
new Point(2, 6), new Point(8, 6)
);
ellipse2 = new Ellipse(
new Point(0, -4), new Point(20, -4),
new Point(0, 12), new Point(20, 12)
);
ellipse3 = new Ellipse(ellipse1);
circle1 = new Circle(
new Point(1, 1), new Point(6, 1),
new Point(1, 6), new Point(6, 6)
);
circle2 = new Circle(
new Point(5, 4), new Point(15, 4),
new Point(5, 14), new Point(15, 14)
);
point1 = new Point(3, 3);
}
}