- Telekom mobilszolgáltatások
- Samsung Galaxy A52s 5G - jó S-tehetség
- Poco F5 - pokolian jó ajánlat
- Xiaomi 15 - kicsi telefon nagy energiával
- Amazfit Active 2 NFC - jó kör
- Samsung Galaxy S23 Ultra - non plus ultra
- Samsung Galaxy S25 Ultra - titán keret, acélos teljesítmény
- Xiaomi 13T és 13T Pro - nincs tétlenkedés
- iPhone topik
- Nokia N8 - vajon elég lesz-e?
Ú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?:))
- Gamer PC-Számítógép! Csere-Beszámítás! I5 10400F / GTX 1070 8GB / 16GB DDR4 / 512 Nvme SSD
- Eladó MacBook Pro 13 (2020) i7 2.3GHz / 16GB / 512GB Asztroszürke
- Kaspersky, BitDefender, Avast és egyéb vírusírtó licencek a legolcsóbban, egyenesen a gyártóktól!
- BESZÁMÍTÁS! ASRock X870 R9 7950X3D 32GB DDR5 1TB SSD RTX 4090 24GB Be quiet Pure Base 501 LX white
- Decathlonos 43-as boxcipő, alig használt, hibátlan állapotban
Állásajánlatok
Cég: Laptopműhely Bt.
Város: Budapest
Cég: Central PC számítógép és laptop szerviz - Pécs
Város: Pécs


