Commit 7116abc8 by Emanuel Lugo

Funciones para ordenar la lista de Cartas agregada

parent 08cbdd65
......@@ -21,5 +21,11 @@ public class Carta {
}
}
import java.util.Comparator;
class SortbyPalo implements Comparator<Carta>
{
// Used for sorting in ascending order of
// Ordenar por Palo
public int compare(Carta a, Carta b)
{
return a.palo.compareTo(b.palo) ;
}
}
\ No newline at end of file
import java.util.Comparator;
class SortbyValor implements Comparator<Carta>
{
// Used for sorting in ascending order of
// Ordenar por Palo
public int compare(Carta a, Carta b)
{
return a.valor.compareTo(b.valor) ;
}
}
\ No newline at end of file
/** */
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.*;
public class pokerGame {
......@@ -18,28 +23,42 @@ public class pokerGame {
return null;
}
public static void main(String[] args) {
pokerGame poker = new pokerGame();
int i;
Carta carta1, carta2, carta3, carta4, carta5 ;
ArrayList<Carta> mano = new ArrayList<Carta>();
carta1 = new Carta("AS");
carta2 = new Carta("2S");
carta3 = new Carta("3S");
carta4 = new Carta("4S");
carta5 = new Carta("5S");
mano.add(carta5) ;
mano.add(carta4) ;
mano.add(carta3) ;
mano.add(carta2) ;
mano.add(carta1) ;
//System.out.println(mano);
for (i=0; i<mano.size(); i++)
System.out.println(mano.get(i).valorPalo() );
Collections.sort(mano, new SortbyPalo());
System.out.println("") ;
for (i=0; i<mano.size(); i++)
System.out.println(mano.get(i).valorPalo());
public static void main(String[] args) {
pokerGame poker = new pokerGame();
int i;
Carta mano[] = new Carta[5];
mano [0] = new Carta("AS");
mano [1] = new Carta("2S");
mano [2]= new Carta("3S");
mano [3]= new Carta("4S");
mano [4]= new Carta("5S");
Collections.sort(mano, new SortbyValor());
System.out.println("") ;
for (i=0; i<5 ; i++)
System.out.println(mano[i].valorPalo());
for (i=0; i<mano.size(); i++)
System.out.println(mano.get(i).valorPalo());
poker.jugadas(mano) ;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment