/** * create a spider with pageProcessor. * * @param pageProcessor pageProcessor * @return new spider * @see PageProcessor */ public static Spider create(PageProcessor pageProcessor) { return new Spider(pageProcessor); }
/** * create a spider with pageProcessor. * * @param pageProcessor pageProcessor * @return new spider * @see PageProcessor */ public static Spider create(PageProcessor pageProcessor) { return new Spider(pageProcessor); }
var spider = new Spider("Skitter the Spider"); spider.walk();
// in real code you would have to build this list and check it is sorted in reverse order // and that the total sum is 100 List<Double> probabilities = Arrays.asList(45, 30, 25); List<Enemy> enemies = Arrays.asList(new Zombie(), new Spider(), new Assassin()); public static Enemy randomEnemy(List<Enemy> enemies, List<Double> probabilities) { double d = Math.random(); double threshold = 0; for (int i = 0; i < probabilities.size(); i++) { threshold += probabilities.get(i) / 100; if (d < threshold) return enemies.get(i); } throw new IllegalArgumentException("Probabilities don't add up to 1. Total: " + threshold); }
/** * @param args the command line arguments */ public static void main(String[] args) throws Exception { System.out.println("starting "); Spider spider = new Spider(); spider.Test(); }
List<Animal> animals = new ArrayList<Animal>(); animals.add(new Cat()); animals.add(new Spider());