Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
JoaquinBaranda
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Joaquin Elias Baranda Ayala
JoaquinBaranda
Commits
ced6b800
Commit
ced6b800
authored
Nov 02, 2021
by
Joaquin Elias Baranda Ayala
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Actualizacion de ejercicio Poker
parent
a91733ef
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
195 additions
and
12 deletions
+195
-12
.vscode/settings.json
+3
-1
Dia 6/ejercicio_poker/Baraja.java
+147
-9
Dia 6/ejercicio_poker/Carta.java
+16
-0
Dia 6/ejercicio_poker/Ejercicio_Poker.java
+29
-2
No files found.
.vscode/settings.json
View file @
ced6b800
{
{
"java.project.sourcePaths"
:
[
"java.project.sourcePaths"
:
[
"Dia 5"
,
"Dia 2"
,
"Dia 2"
,
"Dia
5
"
"Dia
6/ejercicio_poker
"
]
]
}
}
\ No newline at end of file
Dia 6/ejercicio_poker/Baraja.java
View file @
ced6b800
package
ejercicio_poo_ddr_05
;
package
ejercicio_poo_ddr_05
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Comparator
;
public
class
Baraja
{
public
class
Baraja
{
...
@@ -50,9 +54,12 @@ public class Baraja {
...
@@ -50,9 +54,12 @@ public class Baraja {
cartas
[
i
]
=
cartas
[
posAleatoria
];
cartas
[
i
]
=
cartas
[
posAleatoria
];
cartas
[
posAleatoria
]
=
c
;
cartas
[
posAleatoria
]
=
c
;
}
}
this
.
posSiguienteCarta
=
0
;
this
.
posSiguienteCarta
=
0
;
}
}
...
@@ -90,7 +97,7 @@ public class Baraja {
...
@@ -90,7 +97,7 @@ public class Baraja {
for
(
int
i
=
0
;
i
<
cartasDar
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
cartasDar
.
length
;
i
++)
{
cartasDar
[
i
]
=
siguienteCarta
();
cartasDar
[
i
]
=
siguienteCarta
();
}
}
Arrays
.
sort
(
cartasDar
,
Comparator
.
comparing
(
Carta:
:
getNumero
).
reversed
());
return
cartasDar
;
return
cartasDar
;
...
@@ -102,29 +109,160 @@ public class Baraja {
...
@@ -102,29 +109,160 @@ public class Baraja {
public
void
cartasMonton
()
{
public
void
cartasMonton
(
Carta
carta
[]
)
{
Arrays
.
sort
(
carta
,
Comparator
.
comparing
(
Carta:
:
getNumero
).
reversed
());
for
(
int
i
=
0
;
i
<
posSiguienteCarta
;
i
++)
{
for
(
int
i
=
0
;
i
<
posSiguienteCarta
;
i
++)
{
System
.
out
.
println
(
cartas
[
i
]);
System
.
out
.
println
(
carta
[
i
]);
}
}
}
public
void
validacionDoble
(
Carta
carta
[]){
boolean
dobleE
=
false
;
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
for
(
int
j
=
i
+
1
;
j
<
5
;
j
++)
{
if
((
carta
[
i
].
getNumero
())==(
carta
[
j
].
getNumero
())){
dobleE
=
true
;
}
}
}
}
if
(
dobleE
){
System
.
out
.
println
(
"\nEs Par"
);
}
public
void
mostrarBaraja
()
{
}
if
(
cartasDisponible
()
==
0
)
{
System
.
out
.
println
(
"No hay cartas que mostrar"
);
public
void
parDoble
(
Carta
carta
[]){
}
else
{
int
firstDoble
=
0
;
for
(
int
i
=
posSiguienteCarta
;
i
<
cartas
.
length
;
i
++)
{
boolean
exist
=
false
;
System
.
out
.
println
(
cartas
[
i
]);
for
(
int
i
=
0
;
i
<
4
;
i
++){
if
(
carta
[
i
].
getNumero
()==(
carta
[
i
+
1
].
getNumero
())){
if
(
firstDoble
==
0
){
firstDoble
=
carta
[
i
].
getNumero
();
}
else
if
(
carta
[
i
].
getNumero
()!=(
firstDoble
)){
exist
=
true
;
}
}
}
if
(
exist
){
System
.
out
.
print
(
"Es Doble Par "
);
}
}
public
void
cartaMasAlta
(
Carta
carta
[]){
System
.
out
.
print
(
"\nCarta Alta "
+
carta
[
0
]);
}
public
void
trio
(
Carta
carta
[]){
boolean
exist
=
false
;
for
(
int
i
=
0
;
i
<
5
-
2
;
i
++){
if
(
carta
[
i
].
getNumero
()==(
carta
[
i
+
1
].
getNumero
())
&&
carta
[
i
].
getNumero
()==(
carta
[
i
+
2
].
getNumero
())){
exist
=
true
;
break
;
}
}
}
if
(
exist
){
System
.
out
.
print
(
"Es Trio"
);
}
}
}
public
void
full
(
Carta
carta
[]){
boolean
exist
=
false
;
if
(
carta
[
0
].
getNumero
()==(
carta
[
1
].
getNumero
())
&&
carta
[
0
].
getNumero
()==(
carta
[
2
].
getNumero
())
&&
carta
[
3
].
getNumero
()==(
carta
[
4
].
getNumero
())){
exist
=
true
;
}
else
if
(
carta
[
2
].
getNumero
()==(
carta
[
3
].
getNumero
())
&&
carta
[
2
].
getNumero
()==(
carta
[
4
].
getNumero
())
&&
carta
[
0
].
getNumero
()==(
carta
[
1
].
getNumero
())){
exist
=
true
;
}
if
(
exist
){
System
.
out
.
print
(
"\nEs Full "
);
}
}
public
void
escalera
(
Carta
carta
[]){
boolean
exist
=
true
;
for
(
int
i
=
0
;
i
<
4
;
i
++){
if
(
carta
[
i
].
getNumero
()==(
carta
[
i
+
1
].
getNumero
())
||
(
carta
[
i
].
getNumero
()
-
carta
[
i
+
1
].
getNumero
()
)>
1
){
exist
=
false
;
break
;
}
}
if
(
exist
){
System
.
out
.
print
(
"\nEs Escalera"
);
}
}
public
void
color
(
Carta
carta
[]){
int
pA
=
1
;
int
val
;
if
(
carta
[
0
].
getPalo
()==(
carta
[
1
].
getPalo
())
||
carta
[
1
].
getPalo
()==(
carta
[
2
].
getPalo
())){
val
=
0
;
}
else
{
val
=
1
;
}
for
(
int
i
=
val
+
1
;
i
<
4
;
i
++){
if
(
carta
[
val
].
getPalo
()==(
carta
[
i
].
getPalo
()))
{
pA
++;
}
}
if
(
pA
==
4
){
System
.
out
.
print
(
"\nEs Color"
);
}
}
public
void
poker
(
Carta
carta
[]){
boolean
exist
=
false
;
if
(
carta
[
0
].
getNumero
()==(
carta
[
1
].
getNumero
())
&&
carta
[
0
].
getNumero
()==(
carta
[
2
].
getNumero
())
&&
carta
[
0
].
getNumero
()==(
carta
[
3
].
getNumero
())){
exist
=
true
;
}
else
if
(
carta
[
1
].
getNumero
()==(
carta
[
2
].
getNumero
())
&&
carta
[
1
].
getNumero
()==(
carta
[
3
].
getNumero
())
&&
carta
[
1
].
getNumero
()==(
carta
[
4
].
getNumero
())){
exist
=
true
;
}
if
(
exist
){
System
.
out
.
print
(
"\nEs Poker"
);
}
}
public
void
escaleraColor
(
Carta
carta
[]){
boolean
exist
=
true
;
for
(
int
i
=
0
;
i
<
carta
.
length
-
1
;
i
++){
if
(
carta
[
i
].
getNumero
()==(
carta
[
i
+
1
].
getNumero
())
||
(
carta
[
i
].
getNumero
()
-
carta
[
i
+
1
].
getNumero
())
>
1
||
!(
carta
[
0
].
getPalo
().
equals
(
carta
[
i
+
1
].
getPalo
()))){
exist
=
false
;
break
;
}
}
}
if
(
exist
){
System
.
out
.
print
(
"\nEs Escalera Color"
);
}
}
}
}
Dia 6/ejercicio_poker/Carta.java
View file @
ced6b800
...
@@ -5,6 +5,22 @@ public class Carta {
...
@@ -5,6 +5,22 @@ public class Carta {
private
int
numero
;
private
int
numero
;
public
int
getNumero
()
{
return
numero
;
}
public
void
setNumero
(
int
numero
)
{
this
.
numero
=
numero
;
}
public
String
getPalo
()
{
return
palo
;
}
public
void
setPalo
(
String
palo
)
{
this
.
palo
=
palo
;
}
private
String
palo
;
private
String
palo
;
public
static
final
String
[]
PALOS
={
"ESPADAS"
,
"TREBOL"
,
"CORAZON"
,
"DIAMANTE"
};
public
static
final
String
[]
PALOS
={
"ESPADAS"
,
"TREBOL"
,
"CORAZON"
,
"DIAMANTE"
};
...
...
Dia 6/ejercicio_poker/Ejercicio_Poker.java
View file @
ced6b800
...
@@ -5,8 +5,35 @@ public class Ejercicio_Poker {
...
@@ -5,8 +5,35 @@ public class Ejercicio_Poker {
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
Baraja
b
=
new
Baraja
();
Baraja
b
=
new
Baraja
();
b
.
darCartas
(
5
);
b
.
cartasMonton
();
Carta
Cartasm
[]
=
b
.
darCartas
(
5
);
//Carga manual
/*
Carta Cartasm[] = new Carta[]{
new Carta(7, "TREBOL"),
new Carta(7, "TREBOL"),
new Carta(3, "ESPADA"),
new Carta(3, "ESPADA"),
new Carta(3, "ESPADA")};
*/
//Impresion
b
.
cartasMonton
(
Cartasm
);
//Prueba de impresion de validaciones
b
.
validacionDoble
(
Cartasm
);
b
.
parDoble
(
Cartasm
);
b
.
trio
(
Cartasm
);
b
.
full
(
Cartasm
);
b
.
escalera
(
Cartasm
);
b
.
color
(
Cartasm
);
b
.
poker
(
Cartasm
);
b
.
escaleraColor
(
Cartasm
);
b
.
cartaMasAlta
(
Cartasm
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment