Скачиваний:
62
Добавлен:
09.05.2014
Размер:
2.48 Кб
Скачать
package lab1;
import java.util.*;
import java.io.*;

/*
Start class for lab1, var. 103.
*/
public class PointsFilter {

public static void main(String[] args) throws Exception{

byte inputByte[] = new byte[100];
double R = 0;
DataInputStream dataStream = new DataInputStream(System.in);
System.out.println("Enter parameter R:");
try{
dataStream.read(inputByte);
String input = new String(inputByte);
R = Double.parseDouble(input);
if (R < 0)
throw new Exception("Parameter R couldn't be less than 0");
}
catch(IOException ex){
HandleException(ex, "An I/O exception of some sort has occurred. ");
}
catch(NumberFormatException ex) {
HandleException(ex, "Input data couldn't be parsed into double. ");
}
catch(Exception ex) {
HandleException(ex, "");
}


Vector points = new Vector();
points.add(new Coordinate(4, 5));
points.add(new Coordinate(4, -3));
points.add(new Coordinate(-3, -4));
points.add(new Coordinate(-3, 4));
points.add(new Coordinate(0, 1));

CoordinateSpace coordinateSpace = new CoordinateSpace();
try {
coordinateSpace.AddQuarter(new Quadrant(Quarters.FIRST, R));
coordinateSpace.AddQuarter(new LinerQuarter(Quarters.SECOND, 0,
R/2, -R, 0, 0, R/2, Boolean.FALSE));
coordinateSpace.AddQuarter(new LinerQuarter(Quarters.THIRD, -0.5,
-R/2, -R, 0, -R/2, 0, Boolean.TRUE));
coordinateSpace.AddQuarter(new NullQuarter(Quarters.FORTH));
}
catch(Exception ex) {
HandleException(ex, "New coordinate quarter couldn't be added. ");
}

System.out.println("Points:");
Enumeration pointsEnum = points.elements();
while (pointsEnum.hasMoreElements())
{
Coordinate point = (Coordinate)pointsEnum.nextElement();
if (coordinateSpace.Belongs(point).booleanValue())
System.out.println(point.GetX() + " " + point.GetY());
}
}

private static void HandleException(Exception ex, String message) {
System.out.print("Exception: " + message + ex.getMessage());
System.exit(1);
}
}
Соседние файлы в папке lab1