Commit 7116abc8 by Emanuel Lugo

Funciones para ordenar la lista de Cartas agregada

parent 08cbdd65
...@@ -19,6 +19,12 @@ public class Carta { ...@@ -19,6 +19,12 @@ public class Carta {
{ {
return this.valor + this.palo; return this.valor + this.palo;
} }
} }
......
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 { public class pokerGame {
...@@ -18,28 +23,42 @@ public class pokerGame { ...@@ -18,28 +23,42 @@ public class pokerGame {
return null; return null;
} }
public static void main(String[] args) { public static void main(String[] args) {
pokerGame poker = new pokerGame(); pokerGame poker = new pokerGame();
int i; int i;
Carta mano[] = new Carta[5]; Carta carta1, carta2, carta3, carta4, carta5 ;
mano [0] = new Carta("AS"); ArrayList<Carta> mano = new ArrayList<Carta>();
mano [1] = new Carta("2S"); carta1 = new Carta("AS");
mano [2]= new Carta("3S"); carta2 = new Carta("2S");
mano [3]= new Carta("4S"); carta3 = new Carta("3S");
mano [4]= new Carta("5S"); 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());
for (i=0; i<5 ; i++)
System.out.println(mano[i].valorPalo());
poker.jugadas(mano) ; Collections.sort(mano, new SortbyValor());
System.out.println("") ;
for (i=0; i<mano.size(); i++)
System.out.println(mano.get(i).valorPalo());
......
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