Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class ConvexHull{
- public static int loadPoints(int maxPoints, double[] xVal, double[] yVal){
- Scanner scan = new Scanner(System.in);
- System.out.println("Input: ");
- double num = 0;
- int counter = 0;
- boolean alter = false;
- while (scan.hasNext()) {
- num = scan.nextDouble();
- if (num < 0) {
- return counter;
- }
- if (counter > 2*maxPoints ) return counter;
- if (alter){
- yVal[counter] = num;
- counter++;
- alter = false;
- } else {
- xVal[counter] = num;
- alter = true;
- }
- }
- return counter;
- }
- /*public static boolean checkDuplicates(int pointCount, double xVal[], double yVal[]){
- /* public static void computeConvexHull(int pointCount, double xVal[], double yVal[]){
- double m, c;
- put your code here
- for (int i=pointCount; i>=1; i--) {
- for (int j=0; j<i; j++) {
- if(i != j) {
- if(xVal[i] == xVal[j] && yVal[i] == yVal[j]) {
- System.out.println("Error: There are duplicates.")
- return true;
- }
- }
- }
- }
- return false;
- }
- */
- public static void main(String[] args) {
- int maxPoints = 70;
- double xVal[] = new double[maxPoints];
- double yVal[] = new double[maxPoints];
- int pointCount = loadPoints(maxPoints, xVal, yVal);
- System.out.println(pointCount);
- for (int i=0; i < maxPoints; i++) {
- if (xVal[i] != 0) {
- System.out.println("("+ xVal[i] + "," + yVal[i] +")");
- }
- }
- // if ( checkDuplicates(pointCount, xVal, yVal) ) return;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement