package quiniela; import java.util.*; public class PartidoValidado { String juegaEnCasa; String juegaFuera; boolean[] pronostico = new boolean[3]; static String unoequisdos="1X2"; static public char get1X2( int i) { return unoequisdos.charAt(i); } public String getJuegaEnCasa() { return this.juegaEnCasa; } public void setJuegaEnCasa( String _newVal) { this.juegaEnCasa = _newVal ; } public String getJuegaFuera() { return this.juegaFuera; } public void setJuegaFuera( String _newVal) { this.juegaFuera = _newVal ; } public boolean[] getPronostico() { return this.pronostico; } public void setPronostico(boolean[] _newVal) { this.pronostico = pronostico; } // Poner el pronóstico como una cadena. Usa funciones de String, // Mirar en http://java.sun.com/products/jdk/1.2/docs/api/java/lang/String.html public void setPronosticoAsString(String _newVal) throws RuntimeException{ if (_newVal.length() > 3) throw new RuntimeException ( "Pronóstico más largo de la cuenta" ); if (_newVal.length() == 0) throw new RuntimeException ( "No hay pronóstico" ); _newVal =_newVal.toUpperCase(); // System.out.println( "PartidoValidado.setPronosticoAsString" + _newVal ); for ( int j = 0; j < _newVal.length(); j ++ ) { if ( _newVal.charAt(j) != '1' && _newVal.charAt(j) != 'X' && _newVal.charAt(j) != '2' ) { throw new RuntimeException ( "Carácter raro en cadena:"+ _newVal.charAt(j) + " en la posición " + j ); } } for ( int i=0; i < 3; i++ ) { if ( _newVal.indexOf(unoequisdos.charAt(i)) >= 0 ) { this.pronostico[i] = true; } else { this.pronostico[i] = false; } } } public String getAsString() { String str=this.juegaEnCasa + "-" + this.juegaFuera + ": " + this.getPronosticoAsString(); return str; } public String getPronosticoAsString() { String str=""; for ( int i = 0; i < 3; i ++ ) { if ( this.pronostico[i] ) { str += unoequisdos.charAt(i); } } return str; } public String getFormatted() { String str= "