Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.52 KB | None | 0 0
  1. public class Giocatore {
  2.     private String nome;
  3.     private double punteggio;
  4.     private int eta;
  5.  
  6.     class GiocatoreException extends Exception {
  7.         public GiocatoreException(String message){
  8.             System.out.println("ciao mondo exception created");
  9.             super(message);
  10.         }
  11.     }
  12.  
  13.     public Giocatore(String nome,int eta){
  14.         this.nome = nome;
  15.         this.eta = eta;
  16.     }
  17.  
  18.     public Giocatore(String nome,int eta,double punteggio){
  19.         this.nome = nome;
  20.         this.eta = eta;
  21.         this.punteggio = punteggio;
  22.     }
  23.  
  24.     public String getNome(){
  25.         return this.nome;
  26.     }
  27.  
  28.     /*
  29.         try {
  30.             ....
  31.         } catch (GiocatoreException g){
  32.             ...
  33.         } catch (Exception e){
  34.             ....
  35.         }
  36.  
  37.     */
  38.  
  39.     // get punteggio
  40.  
  41.     public void setPunteggio(double punteggio){
  42.         if (punteggio <0){
  43.             throw new GiocatoreException("non puoi usare un punteggio negativo!");
  44.         } else {
  45.             this.punteggio = punteggio;
  46.         }
  47.     }
  48.  
  49.     public getEta(){
  50.         return this.eta;
  51.     }
  52.  
  53.     @Override
  54.     public String toString(){
  55.         // .tohash() .hash() univoca
  56.         // clone() clone
  57.         //System.out.println(...) -> (Object(...)).toString();
  58.         String stampa = "";
  59.         stampa += "nome: " + this.nome;
  60.         stampa += " punteggio:" + this.punteggio;
  61.         ...
  62.  
  63.  
  64.         //stampa = "";
  65.         return stampa;
  66.  
  67.     }
  68.  
  69. }
  70.  
  71. public class Squadra {
  72.     Vector<Giocatore> vector;
  73.  
  74.     public Squadra(){
  75.         vector = new Vector<Giocatore>();
  76.     }
  77.  
  78.     public void aggiungiGiocatore(Giocatore g){
  79.         vector.add(g);
  80.     }
  81.  
  82.     public void stampaSquadra(){
  83.         for(int x=0;x<vector.size();x++){
  84.             System.out.println(vector.get(x)); // .toString()
  85.         }
  86.  
  87.         for (Giocatore g: vector.toArray()){ // vector.toArray() deve IMPLEMENTARE Iterable
  88.             System.out.println(g);
  89.         }
  90.     }
  91.  
  92.  
  93.  
  94. }
  95.  
  96. /*
  97. Interfaccia Iterable:
  98. getPosition()
  99. getElementAt()
  100. getSize()
  101.  
  102. Iterable oggetto = ((Iterable)ogg_gen)
  103.  
  104.  
  105. int x = 0;
  106.  
  107.  
  108.  
  109. for (x=0;oggetto.getSize();x++){
  110.     return getElementAt(x);
  111. }
  112.  
  113. Comparable -> int compare(Oggetto ogg){
  114.     this..... ogg
  115.  
  116.     -1 se è minore
  117.     0
  118.     +1 se è maggiore
  119. }
  120.  
  121. */
  122.  
  123.  
  124. /*
  125.  
  126. ArrayList<Giocatori> gioc = ArrayList<Giocari>();
  127. Giocatori gioc = Giocatori[5]();
  128.  
  129. quando chiami get(x)
  130.  
  131. [x,x,x,x3,x,x,x,x,x]
  132.  
  133. Object ret = prendi_memoria(x3);
  134.  
  135. return ret
  136.  
  137. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement