Új hozzászólás Aktív témák
-
Davs
tag
PetCreator:
//: typeinfo/pets/PetCreator.java
// Creates random sequences of Pets.
package typeinfo.pets;
406
Thinking in Java
Bruce Eckel
import java.util.*;
public abstract class PetCreator {
private Random rand = new Random(47);
// The List of the different types of Pet to create:
public abstract List<Class<? extends Pet>> types();
public Pet randomPet() { // Create one random Pet
int n = rand.nextInt(types().size());
try {
return types().get(n).newInstance();
} catch(InstantiationException e) {
throw new RuntimeException(e);
} catch(IllegalAccessException e) {
throw new RuntimeException(e);
}
}
public Pet[] createArray(int size) {
Pet[] result = new Pet[size];
for(int i = 0; i < size; i++)
result[i] = randomPet();
return result;
}
public ArrayList<Pet> arrayList(int size) {
ArrayList<Pet> result = new ArrayList<Pet>();
Collections.addAll(result, createArray(size));
return result;
}
} ///:~ForNameCreator:
//: typeinfo/pets/ForNameCreator.java
package typeinfo.pets;
import java.util.*;
public class ForNameCreator extends PetCreator {
private static List<Class<? extends Pet>> types =
new ArrayList<Class<? extends Pet>>();
// Types that you want to be randomly created:
private static String[] typeNames = {
"typeinfo.pets.Mutt",
"typeinfo.pets.Pug",
"typeinfo.pets.EgyptianMau",
"typeinfo.pets.Manx",
"typeinfo.pets.Cymric",
Type Information
407
"typeinfo.pets.Rat",
"typeinfo.pets.Mouse",
"typeinfo.pets.Hamster"
};
@SuppressWarnings("unchecked")
private static void loader() {
try {
for(String name : typeNames)
types.add(
(Class<? extends Pet>)Class.forName(name));
} catch(ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
static { loader(); }
public List<Class<? extends Pet>> types() {return types;}
} ///:~
Új hozzászólás Aktív témák
A topicot kiemeltem. Valaki nem akar egy nyitó hsz-t írni?:))
- Synology NAS
- Okos otthon - Home Assistant, openHAB és más nyílt rendszerek
- Házimozi belépő szinten
- Formula-1
- BMW topik
- Rettegés és új ellenfelek: bemutatkozott a Lords of the Fallen II Umbralja
- Netfone
- Nyáron jön a S.T.A.L.K.E.R. 2 első nagy sztori DLC-je, a Cost of Hope
- FOTÓS beárazás
- Audi, Cupra, Seat, Skoda, Volkswagen topik
- További aktív témák...
- iPad Pro M1 11 512GB wifi + Magic Keyboard + Apple Pencil
- 3TB Seagate Barracuda 3,5-es HDD-k
- Ryzen 7 5800X / AIO / NITRO+ RX 9060 XT 16GB / B550M WIFI / 32GB RAM / 1TB NVMe SSD / 650W GOLD
- Lenovo Thinkpad L13 G4 i5-1335u 16 GB 256 GB NVMe 13.3" érintős laptop
- iPhone 17 Air 256 GB Space Black - 100% akku, kártyafüggetlen, több mint 2,5 év gari!
- Új Creative Sound Blaster JAM V2
- Honor 200 Pro 512GB,Újszerű,Dobozaval,12 hónap garanciával
- ÁRGARANCIA!Épített KomPhone i9 14900KF 32/64GB RAM RTX 5070 Ti 16GB GAMER PC termékbeszámítással
- AKCIÓ! EVGA FTW3 Ultra Gaming RTX 3080Ti 12GB videókártya garanciával hibátlan működéssel
- Telefon felvásárlás!! iPhone 14/iPhone 14 Plus/iPhone 14 Pro/iPhone 14 Pro Max
Állásajánlatok
Cég: Laptopműhely Bt.
Város: Budapest

