From ec5bbb7d01d9bb24b9eaf6a93bad4f32b9469693 Mon Sep 17 00:00:00 2001 From: Jose Figueredo Date: Tue, 1 Sep 2020 20:58:45 -0400 Subject: [PATCH] segunda tarea --- VacasToros.java | 157 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ readme.md | 2 ++ 2 files changed, 159 insertions(+) create mode 100644 VacasToros.java create mode 100644 readme.md diff --git a/VacasToros.java b/VacasToros.java new file mode 100644 index 0000000..8424cce --- /dev/null +++ b/VacasToros.java @@ -0,0 +1,157 @@ + + +import java.util.*; + + +public class VacasToros { + + + + private String numero; + private char a[]; + private int vacas; + private int toros; + + public VacasToros(String n){ + this.numero=n; + + for(int i=0;i<4;i++) + { + a[i] =n.charAt(i); + } + + verificar(a); + } + + + public boolean verificar(char a[]){ + int bandera=0; + for(int i=0;i<4;i++) + { + for(int j=0;j<4;j++) + { + if(a[i]==a[j] && i!=j) + { + bandera=1; + j=4; + i=10; + } + } + } + + if(bandera==1) + return false; + return true; + + + } + + + public boolean verificar(String c){ + char d[]= new char[4]; + for(int i=0;i<4;i++) + { + d[i] =c.charAt(i); + } + + + int bandera=0; + for(int i=0;i<4;i++) + { + for(int j=0;j<4;j++) + { + if(d[i]==d[j] && i!=j) + { + bandera=1; + j=4; + i=10; + } + } + } + + if(bandera==1) + return false; + return true; + + + } + public void comparar(String n){ + + char b[]= new char[4]; + + + + for(int i=0;i<4;i++) + { + b[i] =n.charAt(i); + } + + + + for(int i=0;i<4;i++) + { + + if(a[i]==b[i]) + { + toros++; + } + else{ + + for(int j=0;j<4;j++) + { + if (a[i]==b[j]) + { + vacas++; + } + } + + } + } + + + System.out.println("VACAS :"+vacas+" TOROS: "+toros); + + + + } + + + + + + + + + +public static void main(String[] args) { + + VacasToros juego = new VacasToros("1521"); + + + Scanner teclado= new Scanner(System.in); + + String a= teclado.nextLine(); + + String b= teclado.nextLine(); + + + + while(juego.verificar(a) && juego.verificar(b)) + { + + juego.comparar(b); + + // no pude terminar por tiempo + + + + } + + + + +} + + + +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..4ae288d --- /dev/null +++ b/readme.md @@ -0,0 +1,2 @@ +compilar javac VacasToros.java +ejecutar java VacasToros \ No newline at end of file -- libgit2 0.26.0