public Coffee next() {
   try {
     return (Coffee) types[rand.nextInt(types.length)].newInstance();
     // report programmer error at run time
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
Esempio n. 2
0
 public Product next() {
   return new Product(
       rand.nextInt(1000), "Test", Math.round(rand.nextDouble() * 1000.0) + 0.99);
 }