codice:public class Carta { private int seme; private int valore; public Carta(int seme, int valore) { this.seme = seme; this.valore = valore; } public String getSeme() { switch (seme) { case 1: return "Cuori"; case 2: return "Quadri"; case 3: return "Fiori"; case 4: return "Picche"; default: return ""; } } public String getValore() { if ((valore == 1) || (valore > 10)) { switch (valore) { case 1: return "Asso"; case 11: return "Jack"; case 12: return "Donna"; case 13: return "Re"; default: return ""; } } else { return (""+valore); } } public String toString() { return (getValore()+" di "+getSeme()); } }codice:public class Mazzo { private Carta[] mazzo = new Carta[52]; public Mazzo() { int c = 0; for (int j=1; j <=4; j++) { for (int i=1; i <=13; i++) { mazzo[c] = new Carta(j,i); c++; } } } public String toString() { StringBuffer sb = new StringBuffer(); for (int j=0; j < 13; j++) { for (int i = 0; i < 4; i++) { sb.append(mazzo[j + 13 * i].toString() + "\t"); } sb.append("\n"); } return sb.toString(); } public static void main (String args[]) { Mazzo m = new Mazzo(); System.out.print(m.toString()); } }

Rispondi quotando