Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Esercizio L.3.19 #47

Open
rimaout opened this issue Mar 21, 2024 · 1 comment
Open

Esercizio L.3.19 #47

rimaout opened this issue Mar 21, 2024 · 1 comment

Comments

@rimaout
Copy link
Member

rimaout commented Mar 21, 2024

image
@alem1105
Copy link
Member

Da gestire meglio il mescolamento

public class Carta {
    private String seme;
    private int valore;
    public Carta(String seme, int valore) {
        this.seme = seme;
        this.valore = valore;
    }
    public String toString() {
        return valore + " di " + seme;
    }
}

import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Random;

public class MazzoDiCarte {
    private static String[] semi = new String[] {"Quadri", "Cuori", "Fiori", "Picche"};
    private static Random random = new Random();
    private ArrayList<Carta> carte = new ArrayList<Carta>();
    //private Carta[] carte = new Carta[52];
    private int estrazione = 0;
    public void Mescola() {
        if (!carte.isEmpty()) {
            estrazione = random.nextInt(0, carte.size());
        }
        else {
            System.out.println("Mazzo finito");
        }
    }
    public Carta Distribuisci() {
        estrazione = random.nextInt(0, carte.size());
        Carta carta = carte.get(estrazione);
        carte.remove(estrazione);
        return carta;
    }
    public MazzoDiCarte() {
        for (String i : semi) {
            for (int j = 1; j <= 13; j++) {
                carte.add(new Carta(i, j));
            }
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants