Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Giocatore {
- private String nome;
- private double punteggio;
- private int eta;
- class GiocatoreException extends Exception {
- public GiocatoreException(String message){
- System.out.println("ciao mondo exception created");
- super(message);
- }
- }
- public Giocatore(String nome,int eta){
- this.nome = nome;
- this.eta = eta;
- }
- public Giocatore(String nome,int eta,double punteggio){
- this.nome = nome;
- this.eta = eta;
- this.punteggio = punteggio;
- }
- public String getNome(){
- return this.nome;
- }
- /*
- try {
- ....
- } catch (GiocatoreException g){
- ...
- } catch (Exception e){
- ....
- }
- */
- // get punteggio
- public void setPunteggio(double punteggio){
- if (punteggio <0){
- throw new GiocatoreException("non puoi usare un punteggio negativo!");
- } else {
- this.punteggio = punteggio;
- }
- }
- public getEta(){
- return this.eta;
- }
- @Override
- public String toString(){
- // .tohash() .hash() univoca
- // clone() clone
- //System.out.println(...) -> (Object(...)).toString();
- String stampa = "";
- stampa += "nome: " + this.nome;
- stampa += " punteggio:" + this.punteggio;
- ...
- //stampa = "";
- return stampa;
- }
- }
- public class Squadra {
- Vector<Giocatore> vector;
- public Squadra(){
- vector = new Vector<Giocatore>();
- }
- public void aggiungiGiocatore(Giocatore g){
- vector.add(g);
- }
- public void stampaSquadra(){
- for(int x=0;x<vector.size();x++){
- System.out.println(vector.get(x)); // .toString()
- }
- for (Giocatore g: vector.toArray()){ // vector.toArray() deve IMPLEMENTARE Iterable
- System.out.println(g);
- }
- }
- }
- /*
- Interfaccia Iterable:
- getPosition()
- getElementAt()
- getSize()
- Iterable oggetto = ((Iterable)ogg_gen)
- int x = 0;
- for (x=0;oggetto.getSize();x++){
- return getElementAt(x);
- }
- Comparable -> int compare(Oggetto ogg){
- this..... ogg
- -1 se è minore
- 0
- +1 se è maggiore
- }
- */
- /*
- ArrayList<Giocatori> gioc = ArrayList<Giocari>();
- Giocatori gioc = Giocatori[5]();
- quando chiami get(x)
- [x,x,x,x3,x,x,x,x,x]
- Object ret = prendi_memoria(x3);
- return ret
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement