示例#1
0
 private static int findPositionSmallestCircle(ArrayList<GeometricObject> list) {
   Circle exampleCircle = new Circle();
   ArrayList<GeometricObject> onlyCircles =
       new ArrayList<>(); // like method above, sort larger list into only circles
   for (int i = 0; i < list.size(); i++) {
     if (list.get(i).getClass() == exampleCircle.getClass()) {
       onlyCircles.add(list.get(i));
     }
   }
   int indexOfSmallestArea = 0;
   for (int i = 1; i < onlyCircles.size(); i++) { // compare areas within the list
     if (onlyCircles.get(i).getArea() < onlyCircles.get(indexOfSmallestArea).getArea()) {
       indexOfSmallestArea = i;
     }
   }
   return findWithinLargerList(list, onlyCircles, indexOfSmallestArea);
 } // end method
示例#2
0
  public static void main(String[] args) {
    Circle c = new Circle();
    int temp = 0;
    for (int i = 0; ; i++) {

      java.util.Scanner type = new java.util.Scanner(System.in);
      System.out.print("編號" + c.count + "半徑: (-1結束)");
      temp = type.nextInt();
      if (temp == -1) break;
      else {
        c.list[c.count] = temp;
        c.count++;
      }
    }
    while (true) {

      java.util.Scanner type1 = new java.util.Scanner(System.in);
      System.out.print("選擇編號:");
      temp = type1.nextInt();

      if (temp >= c.count) System.out.println("無此編號!");
      else {
        c.num = temp;
        break;
      }
    }
    while (true) {
      java.util.Scanner type2 = new java.util.Scanner(System.in);
      System.out.print("角度:");
      temp = type2.nextInt();
      if (temp > 360) System.out.println("角度無大於360");
      else {
        c.ang = temp;
        break;
      }
    }
    System.out.println("Arc:" + c.Arc());
    System.out.println("Pie:" + c.Pie());
  }