All pastes #462353 Raw Edit

Something

public java v1 · immutable
#462353 ·published 2007-04-28 06:45 UTC
rendered paste body
import java.util.Scanner;public class Driver{  private Shape[] figures;     public static void main(String[] args) {    // TODO code application logic here    new Driver();}    public Driver(){      figures = makeFigures(getInput());     SelectionSortGeneral.sort(figures,figures.length);     for (Shape x : figures){         x.print();     }  }    private Shape randomShape(){     int index = (int)(Math.random() * 4);     switch(index){        case 0: return new Circle();        case 1: return new Circle(4.0,"red",true);        case 2: return new Triangle();        case 3: return new Square();        default: return null;     }  }    private Shape[] makeFigures(int count){      Shape[] figures = new Shape[count];      for(int i = 0; i < count; i++)         figures[i] = randomShape();      return figures;  }    ///* to be used in Task 3    private String[][] getInput(){      String[][] out = new String[6][4];      int i = 0;      Scanner in = new Scanner(System.in);      while (true){         int j = 0;         String line = in.nextLine();         if(line.equals("end")) break;          else{            Scanner linein = new Scanner(line).useDelimiter(",");            while(linein.hasNext()){               String s = linein.next();               out[i][j++] = s;             }          }          i++;       }      return out;  }     private Shape[] makeFigures(String[][] s){     Shape[] out = new Shape[getNotNull(s)];     char ind = ' ';     int i = 0;     for (String[] x : s){        if(x[0] != null){           ind = x[0].charAt(0);              switch (ind) {                case 't':                   out[i++] = new Triangle();                   break;                case 's':                   out[i++] = new Square();                   break;                                //# if the number of not null elements in array x                                 //is 1 then a default Circle object should be created                                //(using the no argument constructor),                case 'c':                    switch (getNotNull(x)){                        case 1:                            out[i++] = new Circle();                            break;                        case 2:                            out[i++] = new Circle((int)s[i][1]);                                            }                                                   break;                default:                    System.out.println("Error - shape not recognized");                   System.exit(0);              }        }     }     return out;  }     private int getNotNull(String[] s){      int count = 0;      for (String x : s){          if (x != null) count++;      }      return count;  }     private int getNotNull(String[][] s){      int count = 0;      for (String[] x : s){          if (x[0] != null) count++;      }      return count;  }  //*/}